﻿#include "LogicActivityModule.h"
#include "LogicService.h"
#include "base/core/com_define.h"
#include "base/core/os/time.h"
#include "base/core/Profiler.h"
#include "base/core/gamemath.h"
#include "Common/Utility/ServerTime.h"
#include "ProtoBuffer/AllProtocol.h"
#include "Access/CharacterDataSet.h"
#include "Character/PlayerMgr.h"
#include "Common/Utility/AccountUtility.h"
#include "Script/ScriptMgr.h"
#include "Character/monster/Monster.h"
#include "Character/drop/Drop.h"
#include "Character/drop/DropMgr.h"
#include "Character/monster/MonsterRefCfg.h"
#include "Common/TableData/ActivityDailyCfg.h"
#include "Activity/GActivity.h"
#include "Activity/GActivityGoblin.h"
#include "Activity/GActivityAncientElf.h"
#include "Activity/GActivityWorldBoss.h"
#include "Activity/GActivitySonOfKilling.h"
#include "Activity/GActivityChaosDragon.h"
#include "Activity/GActivityLostCity.h"
#include "Activity/GActivityMonsAttackCity.h"
#include "Common/TableData/AreaAreaCfg.h"
#include "Common/TableData/NpcNpcCfg.h"
#include "Common/TableData/MonsterMonsterCfg.h"
#include "Common/TableData/AnswerAnswerCfg.h"
#include "Duplicate/DuplicateMgr.h"
#include "Common/TableDataEx/DuplicateCfg.h"
#include "Character/TitlePart.h"
#include "Common/TableData/ActivityDailyCfg.h"
#include "Answer/AnswerMgr.h"
#include "Character/PackagePart.h"
#include "Common/TableData/AreaPathCfg.h"
#include "Common/TableData/ConstantConstantCfg.h"
#include "Character/HuoYueDuPart.h"
#include "Mail/GMailManager.h"
#include "Common/MallDefine.h"
#include "Common/NotifyDefine.h"
#include "Character/welfare/OperateWelfareMgr.h"
#include "Common/TableDataEx/ItemCfg.h"
#include "Common/EventDefine.h"
#include "Common/TableDataEx/DuplicateCfg.h"
using namespace ProtoBuf;

LogicActivityModule::LogicActivityModule()
{
	_activityPool = nullptr;
	_activityGoblinPool = nullptr;
	_activityAncientElfPool = nullptr;
	_activityWorldBossPool = nullptr;
	_activitySonOfKillingPool = nullptr;
	_activityChaoDragonPool = nullptr;
	_activityLostCityPool = nullptr;
	_activityMonsAttackCityPool = nullptr;
	m_mapActivityData.clear();
}

LogicActivityModule::~LogicActivityModule()
{

}


bool LogicActivityModule::Init()
{
	IMessageDispatch *pMessageDispatch = g_GetLogicService()->GetServiceMessageDispatch();
	if (nullptr == pMessageDispatch)
	{
		return false;
	}

	AncientElfCfg ancientCfg;
	if (!LuaGetAncientElfCfg(ancientCfg,1))
	{
		LogErrFmtPrint("[logic] LogicActivityModule::Init....LuaGetAncientElfCfg return false...");
		return false;
	}
	GoblinCfg goblinCfg;
	if (!LuaGetGoblinCfg(goblinCfg,1))
	{
		LogErrFmtPrint("[logic] LogicActivityModule::Init....LuaGetGoblinCfg return false...");
		return false;
	}
	MonsAttackCityCfg attackCfg;
	if (!LuaGetMonsAttackCity(attackCfg))
	{
		LogErrFmtPrint("[logic] LogicActivityModule::Init....LuaGetMonsAttackCity return false...");
		return false;
	}

	pMessageDispatch->registerClientHandler(EMODULE_ID_ACTIVITY, this);
	pMessageDispatch->registerServerHandler(EMODULE_ID_ACTIVITY, this);

	_activityPool = new ObjectPool < GActivity > ;
	MMO_ASSERT(nullptr != _activityPool);
	_activityGoblinPool = new ObjectPool < GActivityGoblin >;
	MMO_ASSERT(nullptr != _activityGoblinPool);
	_activityAncientElfPool = new ObjectPool < GActivityAncientElf >;
	MMO_ASSERT(nullptr != _activityAncientElfPool);
	_activityWorldBossPool = new ObjectPool < GActivityWorldBoss >;
	MMO_ASSERT(nullptr != _activityWorldBossPool);
	_activitySonOfKillingPool = new ObjectPool < GActivitySonOfKilling >;
	MMO_ASSERT(nullptr != _activitySonOfKillingPool);
	_activityChaoDragonPool = new ObjectPool < GActivityChaosDragon >;
	MMO_ASSERT(nullptr != _activityChaoDragonPool);
	_activityLostCityPool = new ObjectPool < GActivityLostCity >;
	MMO_ASSERT(nullptr != _activityLostCityPool);
	_activityMonsAttackCityPool = new ObjectPool < GActivityMonsAttackCity > ;
	MMO_ASSERT(nullptr != _activityMonsAttackCityPool);

	//预先创建出活动管理类
	const ActivityDailyCfgMap* pActivityCfgMap = g_GetActivityDailyCfgTable()->GetActivityDailyCfgMap();
	if (nullptr != pActivityCfgMap)
	{
		unordered_map<int32_t, ActivityDailyCfgInfo>::const_iterator iter = pActivityCfgMap->begin();
		for (; iter != pActivityCfgMap->end(); ++iter)
		{
			if (iter->second.typeId == ATI_WORLD_BOSS ||
				iter->second.typeId == ATI_SON_OF_KILLING ||
				iter->second.typeId == ATI_CHAOS_DRAGON ||
				iter->second.typeId == ATI_LOST_CITY ||
				iter->second.typeId == ATI_MONS_ATTACK_CITY ||
				iter->second.typeId == ATI_ESCORT
				)
			{
				MutStaticActivity(iter->second.activeId);
			}
		}
	}

	if (!g_GetTimerAxis()->SetTimer(1,2 * 1000,this))
	{
		LogErrFmtPrint("[logic] LogicActivityModule::Init....SetTimer return false...");
		return false;
	}


	return true;
}

void LogicActivityModule::UnInit()
{
	g_GetEvent()->UnSubscribeAll(this);
	g_GetTimerAxis()->KillAllTimer(this);

	IMessageDispatch *pMessageDispatch = g_GetLogicService()->GetServiceMessageDispatch();
	if (nullptr == pMessageDispatch)
	{
		return;
	}

	pMessageDispatch->unregisterClientHandler(EMODULE_ID_ACTIVITY);
	pMessageDispatch->unregisterServerHandler(EMODULE_ID_ACTIVITY);

	for (StaticActivityMap::iterator iter = m_mapActivity.begin(); iter != m_mapActivity.end(); ++iter)
	{
		if (nullptr != iter->second)
		{
			iter->second->UnInit();
			RecycleActivity(iter->second);
			iter->second = nullptr;
		}
	}
	m_mapActivity.clear();
	m_mapActivityData.clear();

	MMO_DELETE(_activityPool);
	MMO_DELETE(_activityGoblinPool);
	MMO_DELETE(_activityAncientElfPool);
	MMO_DELETE(_activityWorldBossPool);
	MMO_DELETE(_activitySonOfKillingPool);
	MMO_DELETE(_activityChaoDragonPool);
	MMO_DELETE(_activityLostCityPool);
	MMO_DELETE(_activityMonsAttackCityPool);	
}

void LogicActivityModule::onClientMessage(uint32_t actionId, RECV_PACKAGE &package, uint64_t Id /*= 0*/)
{
	switch (actionId)
	{
	case CLIENT_TO_LOGIC_ACTIVITY_ENTER:
	{
		OnEnterActivityReq(Id, package);
	}
	break;
	case CLIENT_TO_LOGIC_ACTIVITY_LEAVE:
	{

	}
	break;
	case CLIENT_TO_LOGIC_ACTIVITY_TALK:
	{
		OnNpcTalkReq(Id, package);
	}
	break;
	case CLIENT_TO_LOGIC_ACTIVITY_LOST_CITY_SNED:
	{
		OnLostCitySend(Id, package);
	}
	break;
	case CLIENT_TO_CENTER_ACTIVITY_SON_TRACK_INFO:
	{
		OnGetSonTrackInfo(Id, package);
	}
	break;
	case CLIENT_TO_LOGIC_ACTIVITY_SON_POS_INFO:
	{
		OnSonPosInfoReq(Id, package);
	}
	break;
	case CLIENT_TO_LOGIC_ACTIVITY_ANSWER_INFO:
	{
		OnGetAnswerInfo(Id, package);
		break;
	}
	case CLIENT_TO_LOGIC_ACTIVITY_ANSWER_RESULT:
	{
		OnAnswerResult(Id, package);
		break;
	}
	case CLIENT_TO_LOGIC_ACTIVITY_ANSWER_LAST_REWARD:
	{
		OnAnswerGetLastReward(Id, package);
		break;
	}
	default:
		break;
	}
}

void LogicActivityModule::onServerMessage(uint32_t actionId, RECV_PACKAGE &package)
{
	switch (actionId)
	{
	case CENTER_TO_LOGIC_DAILY_UPDATE_NOTIFY:
	{
		DailyUpdate(package);
		break;
	}
	case CENTER_TO_LOGIC_WEEK_UPDATE_NOTIFY:
	{
		WeekUpdate(package);
		break;
	}
	case CENTER_TO_LOGIC_DAILY_ZERO_UPDATE_NOTIFY:
	{
		DailyZeroUpdate(package);
		break;
	}
	case CENTER_TO_LOGIC_WEEK_ZERO_UPDATE_NOTIFY:
	{
		WeekZeroUpdate(package);
		break;
	}
	case CENTER_TO_LOGIC_STATIC_ACTIVITY_OPEN:
	{
		OnStaticActivityOpen(package);
		break;
	}
	case CENTER_TO_LOGIC_STATIC_ACTIVITY_CLOSE:
	{
		OnStaticActivityClose(package);
		break;
	}
	case CENTER_TO_LOGIC_ACTIVITY_GETREWARD:
	{
		OnStaticActivityReward(package);
		break;
	}
	case CENTER_TO_LOGIC_UPDATE_ACTIVITY_INFO:
	{
		OnNotifyActData(package);
		break;
	}
	case LOGIC_TO_CENTER_ACTIVE_ANWSER_END:
	{
		OnNotifyActiveAnswerEnd(package);
		break;
	}
	case CENTER_TO_LOGIC_OPERATE_SET:
	{
		OnOperateSet(package);
		break;
	}
	case CENTER_TO_LOGIC_ACTIVITY_JOIN:
	{
		OnActivityJoin(package);
		break;
	}

	default:
		break;
	}
}

void LogicActivityModule::OnTimer(uint32_t nTimerID)
{
	switch (nTimerID)
	{
	case 1:
		{
			if (g_GetLogicService()->IsConnectCenter())
			{
				//请求活动信息
				LCActivityInfoReq req;
				if (!g_GetLogicService()->SendDataToCenter(EMODULE_ID_ACTIVITY, LOGIC_TO_CENTER_ACTIVITY_INFO, &req))
				{
					MMOLOG_FMT_ERROR("LogicActivityModule::OnTimer....SendDataToCenter... failed....")
				}
				g_GetTimerAxis()->KillTimer(1, this);
			}
		}
		break;
	default:
		break;
	}
}


GActivity *LogicActivityModule::MakeActivityObj(uint32_t activityId)
{
	const ActivityDailyCfgInfo *pActivityCfg = g_GetActivityDailyCfgTable()->GetActivityDailyCfgInfo(activityId);
	if (nullptr == pActivityCfg)
	{
		return nullptr;
	}
	GActivity *pActivity = nullptr;
	switch (pActivityCfg->typeId)
	{
	case ATI_GOBLIN: //哥布枿
	{
		pActivity = _activityGoblinPool->MallocObj();
	}
	break;
	case ATI_ANCIENT_ELF://远古精灵
	{
		pActivity = _activityAncientElfPool->MallocObj();
	}
	break;
	case ATI_WORLD_BOSS: //世界Boss
	{
		pActivity = _activityWorldBossPool->MallocObj();
	}
	break;
	case ATI_SON_OF_KILLING: //杀戮之子
	{
		pActivity = _activitySonOfKillingPool->MallocObj();
	}
	break;
	case ATI_CHAOS_DRAGON: //混沌之龙
	{
		pActivity = _activityChaoDragonPool->MallocObj();
	}
	break;
	case ATI_LOST_CITY:	//遗失之城
	{
		pActivity = _activityLostCityPool->MallocObj();
	}
	break;
	case ATI_MONS_ATTACK_CITY: //怪物攻城
	{
		pActivity = _activityMonsAttackCityPool->MallocObj();
	}
	break;
	case ATI_ESCORT: //公会押镖
	{
		pActivity = _activityPool->MallocObj();
	}
	break;
	}
	if (nullptr != pActivity)
	{
		pActivity->Init(activityId);
		pActivity->SetType((ACTIVITY_TYPE_ID)pActivityCfg->typeId);
	}

	return pActivity;
}

void LogicActivityModule::RecycleActivity(GActivity *pActivity)
{
	if (nullptr == pActivity)
	{
		return;
	}
	pActivity->UnInit();
	//
	int32_t typeId = pActivity->GetType();
	switch (typeId)
	{
	case ATI_GOBLIN:
	{
		_activityGoblinPool->FreeObj((GActivityGoblin*)pActivity);
	}
	break;
	case ATI_ANCIENT_ELF:
	{
		_activityAncientElfPool->FreeObj((GActivityAncientElf*)pActivity);
	}
	break;
	case ATI_WORLD_BOSS:
	{
		_activityWorldBossPool->FreeObj((GActivityWorldBoss*)pActivity);
	}
	break;
	case ATI_SON_OF_KILLING:
	{
		_activitySonOfKillingPool->FreeObj((GActivitySonOfKilling*)pActivity);
	}
	break;
	case ATI_CHAOS_DRAGON:
	{
		_activityChaoDragonPool->FreeObj((GActivityChaosDragon*)pActivity);
	}
	break;
	case ATI_LOST_CITY:
	{
		_activityLostCityPool->FreeObj((GActivityLostCity*)pActivity);
	}
	break;
	case ATI_MONS_ATTACK_CITY:
	{
		_activityMonsAttackCityPool->FreeObj((GActivityMonsAttackCity*)pActivity);
	}
	break;
	case ATI_ESCORT:
	{
		_activityPool->FreeObj(pActivity);
	}
	break;
	default:
	{
		MMO_DELETE(pActivity);
		LogErrFmtPrint("[logic] LogicActivityModule::RecycleActivity...unkonwn activity typeid...typeid:%d ", typeId);
	}
	break;
	}
}

bool LogicActivityModule::OnStaticActivityOpen(RECV_PACKAGE &package)
{
	CLStaticActivityOpenReq req;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("CLStaticActivityOpenReq parse failed...");
		return false;
	}

	//世界Boss活动ID大于0 表示要开启活动
	if (req.worldbossinfo().activityid() > 0)
	{
		GActivity *pActivity = nullptr;
		uint32_t activityId = req.worldbossinfo().activityid();
		uint32_t mapId = req.worldbossinfo().mapid();

		//检查该场景中是否有该地图
		Scene* pScene = g_GetSceneMgr()->GetScene(mapId);
		if (nullptr == pScene)
		{
			MMOLOG_FMT_ERROR("LogicActivityModule::OnStaticActivityOpen world boss open but pScene == nullptr mapid=%d...", mapId);
			return false;
		}

		//如果场景中已经挂载了该活动 那么重新利用该活动对象
		pActivity = FindStaticActivity(activityId);
		if (nullptr != pActivity)
		{
			pActivity->InitWorldBossParam(req.worldbossinfo());
			pActivity->StartActivity();
		}
		else
		{
			MMOLOG_FMT_ERROR("LogicActivityModule::OnStaticActivityOpen world boss open but pActivity == nullptr activityId=%d...", activityId);
			return false;
		}
	}
	//杀戮之子
	if (req.sonofkillinginfo().activityid() > 0)
	{
		GActivity *pActivity = nullptr;
		uint32_t activityId = req.sonofkillinginfo().activityid();
		uint32_t mapId = req.sonofkillinginfo().mapid();

		//检查该场景中是否有该地图
		Scene* pScene = g_GetSceneMgr()->GetScene(mapId);
		if (nullptr == pScene)
		{
			MMOLOG_FMT_ERROR("LogicActivityModule::OnStaticActivityOpen sonofkilling boss open but pScene == nullptr mapid=%d...", mapId);
			return false;
		}

		//如果场景中已经挂载了该活动 那么重新利用该活动对象
		pActivity = FindStaticActivity(activityId);
		if (nullptr != pActivity)
		{
			pActivity->InitSonOfKillingParam(req.sonofkillinginfo());
			pActivity->StartActivity();
		}
		else
		{
			MMOLOG_FMT_ERROR("LogicActivityModule::OnStaticActivityOpen sonofkilling boss open but pActivity == nullptr activityId=%d...", activityId);
			return false;
		}
	}
	//混沌之龙
	if (req.chaosdragoninfo().activityid() > 0)
	{
		GActivity *pActivity = nullptr;
		uint32_t activityId = req.chaosdragoninfo().activityid();
		uint32_t mapId = req.chaosdragoninfo().mapid();
		

		//检查该场景中是否有该地图
		Scene* pScene = g_GetSceneMgr()->GetScene(mapId);
		if (nullptr == pScene)
		{
			MMOLOG_FMT_ERROR("LogicActivityModule::OnStaticActivityOpen world boss open but pScene == nullptr mapid=%d...", mapId);
			return false;
		}

		//如果场景中已经挂载了该活动 那么重新利用该活动对象
		pActivity = FindStaticActivity(activityId);
		if (nullptr != pActivity)
		{
			pActivity->InitChaosDragonParam(req.chaosdragoninfo());
			pActivity->StartActivity();
		}
		else
		{
			MMOLOG_FMT_ERROR("LogicActivityModule::OnStaticActivityOpen world boss open but pActivity == nullptr activityId=%d...", activityId);
			return false;
		}
	}
	//遗失之城
	if (req.lostcityinfo().activityid() > 0)
	{
		GActivity *pActivity = nullptr;
		uint32_t activityId = req.lostcityinfo().activityid();
		uint32_t mapId = req.lostcityinfo().mapid();

		//检查该场景中是否有该地图
		Scene *pScene = g_GetSceneMgr()->GetScene(mapId);
		if (nullptr == pScene)
		{
			MMOLOG_FMT_ERROR("LogicActivityModule::OnStaticActivityOpen monsattackcity open but pScene == nullptr mapid=%d, actid:%u ...", mapId,activityId);
			return false;
		}

		//如果场景中已经挂载了该活动 那么重新利用该活动对象
		pActivity = FindStaticActivity(activityId);
		if (nullptr != pActivity)
		{
			pActivity->InitLostCityParam(req.lostcityinfo());
			pActivity->StartActivity();
		}
		else
		{
			MMOLOG_FMT_ERROR("LogicActivityModule::OnStaticActivityOpen lostcity open but pActivity == nullptr activityId=%d...", activityId);
			return false;
		}
	}
	//怪物攻城
	if (req.monsattackcity().activityid() > 0)
	{
		GActivity *pActivity = nullptr;
		uint32_t activityId = req.monsattackcity().activityid();
		uint32_t mapId = req.monsattackcity().mapid();

		//检查该场景中是否有该地图
		Scene *pScene = g_GetSceneMgr()->GetScene(mapId);
		if (nullptr == pScene)
		{
			MMOLOG_FMT_ERROR("LogicActivityModule::OnStaticActivityOpen monsattackcity open but pScene == nullptr mapid=%d, actid:%u ...", mapId, activityId);
			return false;
		}

		//如果场景中已经挂载了该活动 那么重新利用该活动对象
		pActivity = FindStaticActivity(activityId);
		if (nullptr != pActivity)
		{
			if (pActivity->InitMonsAttackCity(req.monsattackcity()))
			{
				pActivity->StartActivity();
			}
			else
			{
				MMOLOG_FMT_ERROR("LogicActivityModule::OnStaticActivityOpen monsattackcity open    but pActivity->InitMonsAttackCity failed... activityId=%u...", activityId);
			}
		}
		else
		{
			MMOLOG_FMT_ERROR("LogicActivityModule::OnStaticActivityOpen monsattackcity open but pActivity == nullptr activityId=%u...", activityId);
			return false;
		}
	}

	return true;
}

bool LogicActivityModule::OnStaticActivityClose(RECV_PACKAGE &package)
{
	CLStaticActivityCloseReq req;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("CLStaticActivityCloseReq parse failed...");
		return false;
	}

	//uint32_t mapId = req.mapid();
	uint32_t activityId = req.activityid();

	CloseStaticActivity(activityId);
	return true;
}

bool LogicActivityModule::OnStaticActivityReward(RECV_PACKAGE &package)
{
	CLActivityGetReward req;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("CLActivityGetReward parse failed...");
		return false;
	}

	CharIDType charId = req.charid();
	Player* pPlayer = g_GetCreatureMgr()->GetPlayer(charId);
	if (nullptr == pPlayer)
	{
		MMOLOG_FMT_ERROR("CLActivityGetReward but nullptr == pPlayer...");
		return false;
	}

	uint32_t titleId = req.titleid();
	uint32_t leftTime = req.lefttime();
	if (titleId > 0)
	{
		TitlePart* pTtilePart = dynamic_cast<TitlePart*>(pPlayer->GetPart(PART_TITLE));
		if (nullptr == pTtilePart)
		{
			MMOLOG_FMT_ERROR("CLActivityGetReward but nullptr == pTtilePart...");
			return false;
		}

		pTtilePart->FinishTitle(titleId, leftTime);
	}

	uint32_t boxId = req.itemid();
	if (boxId > 0)
	{
		VEC_INT32 vecBox;
		vecBox.push_back(boxId);
		SItemSourceParam sourceParam;
		if (req.rewardtype() >= (uint32_t)ENotifyType_Item_Limit)
			return true;

		sourceParam.notifySource = (ENotifyType)req.rewardtype();
		if (g_GetDropMgr()->PlayerAddBox(pPlayer, vecBox, sourceParam) != RET_SUCCESS)
		{
			std::vector<ItemProtoInfo> vecProto;
			int32_t gold, bindnum, diamnum;
			BoxCondCfg boncfg;
			g_GetDropMgr()->GetBoxCond(pPlayer, boncfg);
			g_GetItemMgr()->CreateBoxDropItem(boxId, vecProto, gold, bindnum, diamnum, boncfg);
			if (sourceParam.notifySource == ENotifyType_Item_LostCity)
			{
				//发放邮件
				string strTopic = "公会战奖励";
				string strContent = "你在公会战活动中，通过积分领取获得物品！";
				g_GetGMailMgr()->SendSystemMail(pPlayer->GetId(), strTopic, strContent, 0, 0, 0, 0, 0, vecProto);
			}
		}
	}
	return true;
}

//中心服通知逻辑服活动数据
bool LogicActivityModule::OnNotifyActData(RECV_PACKAGE &package)
{
	CLUpdateActivityInfoRsp rsp;
	if (!rsp.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("CLUpdateActivityInfoRsp parse failed...");
		return false;
	}
	if (!rsp.has_act_info())
	{
		return false;
	}
	const ActMultDataProto &protoMult = rsp.act_info();
	int32_t isize = protoMult.data_lst_size();
	for (int32_t i = 0; i < isize; ++i)
	{
		const ActDataProto &proto = protoMult.data_lst(i);
		uint32_t actId = proto.actid();
		int32_t state = proto.state();
		uint64_t beginTime = proto.begin_time();
		uint64_t endTime = proto.end_time();

		ActDataMap::iterator iter = m_mapActivityData.find(actId);
		if (iter != m_mapActivityData.end())
		{
			iter->second.state = state;
			iter->second.beginTime = beginTime;
			iter->second.endTime = endTime;
		}
		else
		{
			ActData stData;
			stData.actId = actId;
			stData.state = state;
			stData.beginTime = beginTime;
			stData.endTime = endTime;
			m_mapActivityData[actId] = stData;
		}
		//
		LogInfoFmtPrint("[logic] OnNotifyActData...zid:%d, id:%d, actid:%u, state:%d,begintime:%lu, endtime:%lu ", g_GetLogicService()->GetZID(), g_GetLogicService()->GetID(), actId, state,beginTime,endTime);
		//
		g_GetCreatureMgr()->UpdateActivityState(actId);
	}
	return true;
}

//中心服通知逻辑服答题活动结束
bool LogicActivityModule::OnNotifyActiveAnswerEnd(RECV_PACKAGE &package)
{
	//清空上线玩家的所有答题活动数据
	g_GetCreatureMgr()->ClearAllPlayerActiveAnswerData();
	return true;
}

//中心服通知逻辑服运营设置
bool LogicActivityModule::OnOperateSet(RECV_PACKAGE &package)
{
	CenterToLogicOperateSet operateSet;
	if (!operateSet.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("OnOperateSet parse failed...");
		return false;
	}

	switch (operateSet.operate_type())
	{
	case Mall_Operate_SetType_Goals7Day:
	{
		g_GetOperateWelfareMgr()->SetGoal7DaysDisount(operateSet.value());
	}
	break;

	default:
		break;
	}
	return true;
}

//中心服通知逻辑服角色完成活动
bool LogicActivityModule::OnActivityJoin(RECV_PACKAGE &package)
{
	CLActivityJoinNotify notify;
	if (!notify.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("CLActivityJoinNotify parse failed...");
		return false;
	}
	//完成活动
	CharIDType charid = notify.charid();
	FinishActEvent finishEvent;
	finishEvent.activityId = notify.activityid();
	finishEvent.cid = charid;
	g_GetEvent()->FireExecute(EVENT_FINISH_ACTIVITY, charid, CREATURE_PLAYER, &finishEvent, sizeof(FinishActEvent));
	return true;
}

bool LogicActivityModule::Update(uint64_t tick)
{
	UpdateActivity();
	return true;
}

void LogicActivityModule::DailyUpdate(RECV_PACKAGE &package)
{
	CenterDailyUpdateNotify notify;
	if (!notify.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("CenterDailyUpdateNotify parse failed...");
		return;
	}
	uint64_t unixSec = notify.updatedailytime();
	LogInfoFmtPrint("[logic] LogicActivityModule::DailyUpdate...zid:%d, id:%d,unixSec:%lu ", g_GetLogicService()->GetZID(), g_GetLogicService()->GetID(), unixSec);
	g_GetLogicService()->DailyUpdate(unixSec);
}

void LogicActivityModule::WeekUpdate(RECV_PACKAGE &package)
{
	CenterWeekUpdateNotify notify;
	if (!notify.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("CenterWeekUpdateNotify parse failed...");
		return;
	}
	uint64_t unixSec = notify.updatedailytime();
	LogInfoFmtPrint("[logic] LogicActivityModule::WeekUpdate...zid:%d, id:%d,unixSec:%lu ", g_GetLogicService()->GetZID(), g_GetLogicService()->GetID(), unixSec);
	g_GetLogicService()->WeekUpdate(unixSec);
}

void LogicActivityModule::DailyZeroUpdate(RECV_PACKAGE &package)
{
	CenterDailyZeroUpdateNotify notify;
	if (!notify.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("CenterDailyZeroUpdateNotify parse failed...");
		return;
	}
	uint64_t unixSec = notify.updatedailytime();
	LogInfoFmtPrint("[logic] LogicActivityModule::DailyZeroUpdate...zid:%d, id:%d,unixSec:%lu ", g_GetLogicService()->GetZID(), g_GetLogicService()->GetID(), unixSec);
	g_GetLogicService()->DailyZeroUpdate(unixSec);
}

void LogicActivityModule::WeekZeroUpdate(RECV_PACKAGE &package)
{
	CenterWeekZeroUpdateNotify notify;
	if (!notify.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("CenterWeekZeroUpdateNotify parse failed...");
		return;
	}
	uint64_t unixSec = notify.updatedailytime();
	LogInfoFmtPrint("[logic] LogicActivityModule::WeekZeroUpdate...zid:%d, id:%d,unixSec:%lu ", g_GetLogicService()->GetZID(), g_GetLogicService()->GetID(), unixSec);
	g_GetLogicService()->WeekZeroUpdate(unixSec);
}

bool LogicActivityModule::OnEnterActivityReq(CharIDType charID, RECV_PACKAGE &package)
{
	EnterActivityReq req;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		LogErrFmtPrint("[center] LogicActivityModule::EnterActivityReq prase failed...");
		return false;
	}
	int32_t actId = req.activityid();
	int32_t dupId = req.dup_id();
	const ActivityDailyCfgInfo *pActivityCfg = g_GetActivityDailyCfgTable()->GetActivityDailyCfgInfo(actId);
	if (nullptr == pActivityCfg)
	{
		LogErrFmtPrint("[center] LogicActivityModule::EnterActivityReq  .. nullptr == pActivityCfg  actid:%d ", actId);
		return false;
	}

	Player *pPlayer = g_GetCreatureMgr()->GetPlayer(charID);
	if (nullptr == pPlayer)
	{
		return false;
	}
	int32_t ret = RET_SUCCESS;
	//检查是否在副本中了 任何活动都是以副本的形式存在 如果已经进入过副本了 那么不能重复在进入了
	if (ATI_TOWER == pActivityCfg->typeId
		|| ATI_GUARD == pActivityCfg->typeId
		|| ATI_CLOUD == pActivityCfg->typeId
		)
	{
		if (ATI_CLOUD == pActivityCfg->typeId)
		{
			dupId = g_GetDuplicateCfgMgr()->GetCloudDupId();
		}
		const DuplicateDuplicateCfgInfo *pDuplicateCfg = g_GetDuplicateDuplicateCfgTable()->GetDuplicateDuplicateCfgInfo(dupId);
		if (nullptr == pDuplicateCfg)
		{
			LogErrFmtPrint("[logic] LogicActivityModule::EnterActivityReq  .. nullptr == pDuplicateCfg  actid:%d ,dupid:%d ", actId, dupId);
			return false;
		}
		if (
			((int32_t)EDuplicateType::EDuplicateType_Tower == pDuplicateCfg->duplicateType && ATI_TOWER == pActivityCfg->typeId)
			|| ((int32_t)EDuplicateType::EDuplicateType_Guard == pDuplicateCfg->duplicateType && ATI_GUARD == pActivityCfg->typeId)
			|| ((int32_t)EDuplicateType::EDuplicateType_Cloud == pDuplicateCfg->duplicateType && ATI_CLOUD == pActivityCfg->typeId)
			)
		{
			//塔防或者守护需要判断是否能进副朿
			Part *pDuplicatePart = pPlayer->GetPart(PART_DUPLICATE);
			if (nullptr == pDuplicatePart)
			{
				LogErrFmtPrint("[center] LogicActivityModule::EnterActivityReq  .. nullptr == pDuplicatePart  charid:%lu, actid:%d ", charID, actId);
				return false;
			}
			//进副本校验
			ret = pDuplicatePart->CanEnterDup(dupId);
		}
		else
		{
			LogErrFmtPrint("[center] LogicActivityModule::EnterActivityReq  .. duplicate type error or  activity type error  actid:%d, acttype:%d ,dupid:%d, duptype:%d  ", actId, pActivityCfg->typeId, dupId, pDuplicateCfg->duplicateType);
			return false;
		}
	}
	if (RET_SUCCESS != ret)
	{
		EnterActivityRsp rsp;
		rsp.set_ret(ret);
		pPlayer->SendDataToClient(EMODULE_ID_ACTIVITY, LOGIC_TO_CLIENT_ACTIVITY_ENTER, &rsp);

		return false;
	}

	//通过通知中心服进入活势
	CenterEnterActivityReq centerReq;
	centerReq.set_activityid(req.activityid());
	centerReq.set_charid(charID);
	centerReq.set_dup_id(dupId);
	g_GetLogicService()->SendDataToCenter(EMODULE_ID_ACTIVITY, CENTER_TO_LOGIC_ACTIVITY_ENTER, &centerReq);

	return true;
}

bool LogicActivityModule::OnLeaveActivityReq(CharIDType charID, RECV_PACKAGE &package)
{
	LeaveActivityReq req;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		LogErrFmtPrint("[center] LogicActivityModule::OnLeaveActivityReq prase failed...");
		return false;
	}

	Player *pPlayer = g_GetCreatureMgr()->GetPlayer(charID);
	if (nullptr == pPlayer)
	{
		return false;
	}

	//判断是否在活动中 如果是走离开活动副本流程

	return true;
}

bool LogicActivityModule::OnNpcTalkReq(CharIDType charID, RECV_PACKAGE &package)
{
	ActivityTalkReq req;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		LogErrFmtPrint("[center] LogicActivityModule::OnNpcTalkReq  ActivityTalkReq prase failed...");
		return false;
	}
	Player *pPlayer = g_GetCreatureMgr()->GetPlayer(charID);
	if (nullptr == pPlayer)
	{
		return false;
	}
	uint32_t activityId = req.activity_id();
	uint64_t npcCid = req.npc_cid();
	int32_t reply = req.reply();
	LogDebugFmtPrint("[logic] LogicActivityModule::OnNpcTalkReq...actid:%u, npcCid:%lu, reply:%d ", activityId,npcCid,reply);
	const ActivityDailyCfgInfo *pActivityCfg = g_GetActivityDailyCfgTable()->GetActivityDailyCfgInfo(activityId);
	if (nullptr == pActivityCfg)
	{
		LogErrFmtPrint("[logic] LogicActivityModule::OnNpcTalkReq.... nullptr == pActivityCfg....actid:%u ", activityId);
		return false;
	}
	if (ATI_GOBLIN != pActivityCfg->typeId && ATI_ANCIENT_ELF != pActivityCfg->typeId)
	{
		//目前只有哥布林和远古精灵两个活动需要NPC对话
		return false;
	}
	int8_t type = 0;
	int32_t ret = RET_FAIL;
	uint32_t sceneId = pPlayer->GetSceneId();
	IDuplicate *pDuplicate = g_GetDuplicateMgr()->GetDuplicate(sceneId);
	if (nullptr == pDuplicate)
	{
		//不在工会场景内
		ret = RET_ACTIVITY_NOT_IN_UNION_HOME_SCENE;
	}
	else if ((int8_t)EDuplicateType::EDuplicateType_UnionHome != pDuplicate->GetType())
	{
		//不在工会场景内
		ret = RET_ACTIVITY_NOT_IN_UNION_HOME_SCENE;
	}
	else
	{
		ret = pDuplicate->NpcTalk(charID, activityId, npcCid, reply, type);
	}
	ActivityTalkRsp rsp;
	rsp.set_retcode(ret);
	rsp.set_reply(type);
	rsp.set_npc_cid(npcCid);
	pPlayer->SendDataToClient(EMODULE_ID_ACTIVITY, LOGIC_TO_CLIENT_ACTIVITY_TALK, &rsp);

	return true;
}

bool LogicActivityModule::OnLostCitySend(CharIDType charID, RECV_PACKAGE &package)
{
	ActivityLostCitySend req;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		LogErrFmtPrint("[logic] LogicActivityModule::OnLostCitySend  ActivityTalkReq prase failed...");
		return false;
	}

	Player *pPlayer = g_GetCreatureMgr()->GetPlayer(charID);
	if (nullptr == pPlayer)
	{
		LogErrFmtPrint("[logic] LogicActivityModule::OnLostCitySend pPlayer == nullptr...charId:%llu", charID);
		return false;
	}

	//LogInfoFmtPrint("[logic]+++++++++++++++++++++++++++speed+++++++++++++++++++++");

	GActivity* pActivity = FindStaticActivity(req.activityid());
	if (pActivity == nullptr)
	{
		LogErrFmtPrint("[logic] LogicActivityModule::OnLostCitySend pActivity == nullptr...activityid:%d", req.activityid());
		return false;
	}

	GActivityLostCity *pLostCity = dynamic_cast<GActivityLostCity*>(pActivity);
	if (pLostCity && pLostCity->IsRuning())
	{
		pLostCity->Teleport(pPlayer, req.areaid());
	}

	return true;
}

bool LogicActivityModule::OnGetSonTrackInfo(CharIDType charID, RECV_PACKAGE &package)
{
	ActivitySonOfKillingTrackReq req;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		MMOLOG_FMT_ERROR("[logic] LogicActivityModule::OnGetSonTrackInfo ActivitySonOfKillingTrackReq parse failed...");
		return false;
	}

	Player *pPlayer = g_GetCreatureMgr()->GetPlayer(charID);
	if (nullptr == pPlayer)
	{
		LogErrFmtPrint("[logic] LogicActivityModule::OnGetSonTrackInfo pPlayer == nullptr...charId:%llu", charID);
		return false;
	}

	GActivity* pActivity = FindStaticActivity(req.activityid());
	if (pActivity == nullptr)
	{
		LogErrFmtPrint("[logic] LogicActivityModule::OnGetSonTrackInfo pActivity == nullptr...activityid:%d", req.activityid());
		return false;
	}

	if (req.type() == ATI_SON_OF_KILLING)
	{
		GActivitySonOfKilling *pSonOfKilling = dynamic_cast<GActivitySonOfKilling*>(pActivity);
		if (pSonOfKilling/* && pSonOfKilling->IsRuning()*/)
		{
			ActivitySonOfKillingTrackRsp rsp;
			rsp.set_activityid(req.activityid());
			pSonOfKilling->GetSonOfKillingTrackInfo(rsp);
			pPlayer->SendDataToClient(EMODULE_ID_ACTIVITY, CENTER_TO_CLIENT_ACTIVITY_SON_TRACK_INFO, &rsp);
		}
	}
	else if (req.type() == ATI_CHAOS_DRAGON)
	{
		GActivityChaosDragon *pChaosDragon = dynamic_cast<GActivityChaosDragon*>(pActivity);
		if (pChaosDragon/* && pChaosDragon->IsRuning()*/)
		{
			ActivitySonOfKillingTrackRsp rsp;
			rsp.set_activityid(req.activityid());
			pChaosDragon->GetBossInfo(rsp);
			pPlayer->SendDataToClient(EMODULE_ID_ACTIVITY, CENTER_TO_CLIENT_ACTIVITY_SON_TRACK_INFO, &rsp);
		}
	}
	else
	{
		LogErrFmtPrint("[logic] LogicActivityModule::OnGetSonTrackInfo type is error...type:%d", req.type());
		return false;
	}

	return true;
}

bool LogicActivityModule::OnSonPosInfoReq(CharIDType charId, RECV_PACKAGE &package)
{
	ProtoBuf::ActivitySonOfKillingPosInfoReq req;
	ProtoBuf::ActivitySonOfKillingPosInfoRsp rsp;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		LogErrFmtPrint("[logic] OnSonPosInfoReq parse failed...");
		return false;
	}
	StaticActivityMap::iterator iter = m_mapActivity.begin();
	for (; iter != m_mapActivity.end(); ++iter)
	{
		if (nullptr != iter->second &&
			iter->second->IsRuning() &&
			iter->second->GetType() == ATI_SON_OF_KILLING)
		{
			GActivitySonOfKilling* pActivity = dynamic_cast<GActivitySonOfKilling*>(iter->second);
			if (nullptr != pActivity)
			{
				pActivity->GetSonOfKillingPosInfo(rsp);
				break;
			}
		}
	}

	g_GetLogicService()->SendDataToClient(charId, EMODULE_ID_ACTIVITY, LOGIC_TO_CLIENT_ACTIVITY_SON_POS_INFO, &rsp);
	return true;
}

uint32_t LogicActivityModule::GetSonOfKillingMonsterId()
{
	StaticActivityMap::iterator iter = m_mapActivity.begin();
	for (; iter != m_mapActivity.end(); ++iter)
	{
		if (nullptr != iter->second &&
			iter->second->IsRuning() &&
			iter->second->GetType() == ATI_SON_OF_KILLING)
		{
			GActivitySonOfKilling* pActivity = dynamic_cast<GActivitySonOfKilling*>(iter->second);
			if (nullptr != pActivity)
			{
				return pActivity->GetMonsterId();
			}
		}
	}

	return 0;
}

uint32_t LogicActivityModule::GetSonOfKillingExtraDropId()
{
	StaticActivityMap::iterator iter = m_mapActivity.begin();
	for (; iter != m_mapActivity.end(); ++iter)
	{
		if (nullptr != iter->second &&
			iter->second->IsRuning() &&
			iter->second->GetType() == ATI_SON_OF_KILLING)
		{
			GActivitySonOfKilling* pActivity = dynamic_cast<GActivitySonOfKilling*>(iter->second);
			if (nullptr != pActivity)
			{
				return pActivity->GetDropId();
			}
		}
	}

	return 0;
}

bool LogicActivityModule::BossCanAttack(Player *p, CharIDType monsterCid)
{
	StaticActivityMap::iterator iter = m_mapActivity.begin();
	for (; iter != m_mapActivity.end(); ++iter)
	{
		if (nullptr == iter->second || !iter->second->IsRuning())	continue;
		if (iter->second->GetType() == ATI_LOST_CITY)
		{
			GActivityLostCity *pActivity = dynamic_cast<GActivityLostCity*>(iter->second);
			if (nullptr != pActivity)
				return pActivity->CanAttack(p, monsterCid);
				//if (!pActivity->CanAttack(p, monsterCid))	
				//	return false;
		}
	}

	return true;
}

bool LogicActivityModule::CanAddHateList(Player *killer, Player *deader)
{
	StaticActivityMap::iterator iter = m_mapActivity.begin();
	for (; iter != m_mapActivity.end(); ++iter)
	{
		if (nullptr == iter->second || !iter->second->IsRuning())	continue;
		if (iter->second->GetType() == ATI_LOST_CITY)
		{
			GActivityLostCity *pActivity = dynamic_cast<GActivityLostCity*>(iter->second);
			if (nullptr != pActivity)
				return pActivity->CanAddHateList(killer, deader);
		}
	}

	return true;
}

bool LogicActivityModule::RemitSonPKPunish(uint32_t sceneId)
{
	StaticActivityMap::iterator iter = m_mapActivity.begin();
	for (; iter != m_mapActivity.end(); ++iter)
	{
		if (nullptr == iter->second || !iter->second->IsRuning())	continue;
		if (iter->second->GetType() == ATI_SON_OF_KILLING)
		{
			GActivitySonOfKilling *pActivity = dynamic_cast<GActivitySonOfKilling*>(iter->second);
			if (nullptr != pActivity)
				return pActivity->RemitPKPunish(sceneId);
		}
	}

	return false;
}

bool LogicActivityModule::CanTransScene(Player *p)
{
	StaticActivityMap::iterator iter = m_mapActivity.begin();
	for (; iter != m_mapActivity.end(); ++iter)
	{
		if (nullptr == iter->second)	continue;
		if (iter->second->GetType() == ATI_LOST_CITY)
		{
			if (!iter->second->IsRuning())	return true;
			GActivityLostCity *pActivity = dynamic_cast<GActivityLostCity*>(iter->second);
			if (nullptr == pActivity)		return true;
			return !pActivity->IsInScene(p);
		}
	}

	return true;
}

//死亡是否能掉落
bool LogicActivityModule::CanDeadDrop(Player *p)
{
	StaticActivityMap::iterator iter = m_mapActivity.begin();
	for (; iter != m_mapActivity.end(); ++iter)
	{
		if (nullptr == iter->second)	continue;
		if (iter->second->GetType() == ATI_LOST_CITY)
		{
			if (!iter->second->IsRuning())	return true;
			GActivityLostCity *pActivity = dynamic_cast<GActivityLostCity*>(iter->second);
			if (nullptr == pActivity)		return true;
			return !pActivity->IsInScene(p);
		}
	}

	return true;
}

void LogicActivityModule::OnJoinUnion(Player *p)
{
	StaticActivityMap::iterator iter = m_mapActivity.begin();
	for (; iter != m_mapActivity.end(); ++iter)
	{
		if (nullptr == iter->second || iter->second->GetType() != ATI_LOST_CITY || !iter->second->IsRuning())	continue;
		GActivityLostCity *pActivity = dynamic_cast<GActivityLostCity*>(iter->second);
		if (nullptr != pActivity)
		{
			pActivity->OnJoinUnion(p);
			break;
		}
	}
}

void LogicActivityModule::OnQuitUnion(Player *p)
{
	StaticActivityMap::iterator iter = m_mapActivity.begin();
	for (; iter != m_mapActivity.end(); ++iter)
	{
		if (nullptr == iter->second || iter->second->GetType() != ATI_LOST_CITY || !iter->second->IsRuning())	continue;
		GActivityLostCity *pActivity = dynamic_cast<GActivityLostCity*>(iter->second);
		if (nullptr != pActivity)
		{
			pActivity->OnQuitUnion(p);
			break;
		}
	}
}

void LogicActivityModule::OnDisconnect(Player *p)
{
	StaticActivityMap::iterator iter = m_mapActivity.begin();
	for (; iter != m_mapActivity.end(); ++iter)
	{
		if (nullptr == iter->second || iter->second->GetType() != ATI_LOST_CITY || !iter->second->IsRuning())	continue;
		GActivityLostCity *pActivity = dynamic_cast<GActivityLostCity*>(iter->second);
		if (nullptr != pActivity)
		{
			pActivity->OnDisconnect(p);
			break;
		}
	}
}

//获取哥布林LUA配置
bool LogicActivityModule::LuaGetGoblinCfg(GoblinCfg &cfg,int32_t valueLev)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	if (nullptr == pScript)
	{
		LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg... nullptr == pScript, valueLev:%d ", valueLev);
		return false;
	}
	luabridge::LuaRef refRet(pScript->GetState());
	if (!pScript->CallTableFuncRet("Activity", "LuaGetGoblinCfg", refRet, valueLev))
	{
		LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg... pScript->CallTableFuncRet return false...valueLev:%d ", valueLev);
		return false;
	}
	if (refRet.isNil())
	{
		LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg... refRet.isNil()...valueLev:%d ", valueLev);
		return false;
	}
	/*
	-- 最大npc数量
	['max_npc_num'] = 20,
	-- 当前同时存在的npc数量
	['cur_npc_num'] = 10,
	-- npc id
	['npc_id'] = 3001,
	-- npc的存活时闿读条时间)，单位：秿
	['npc_life_sec'] = 15,
	-- 刷新的区域ID列表
	['fresh_area'] = {1001,1002},
	-- 偷取的公会资釿lev:工会等级 ,  min_steal：偷取的最小工会资釿 max_steal：偷取的最大工会资釿
	['steal_money'] = {
	{ ['lev'] = 1, ['min_steal'] = 5,['max_steal'] = 10 },
	{ ['lev'] = 2, ['min_steal'] = 5,['max_steal'] = 10 },
	{ ['lev'] = 3, ['min_steal'] = 5,['max_steal'] = 10 },
	{ ['lev'] = 4, ['min_steal'] = 5,['max_steal'] = 10 },
	{ ['lev'] = 5, ['min_steal'] = 5,['max_steal'] = 10 }
	},
	-- 哥布林怪物ID，刷在位面中
	['fresh_mons'] = {
	{ ['mons_id'] = 2001, ['mons_num'] = 2 },
	{ ['mons_id'] = 2002, ['mons_num'] = 2 }
	},
	-- 哥布林boss ID
	['boss_id'] = 2003,
	-- 哥布林boss出生区域
	['boss_born_area'] = 1003,

	*/

	//检查校验字殿
	if (!refRet.isTable()
		|| !refRet["max_npc_num"].isNumber()
		|| !refRet["cur_npc_num"].isNumber()
		|| !refRet["npc_id"].isNumber()
		|| !refRet["npc_life_sec"].isNumber()
		|| !refRet["boss_id"].isNumber()
		|| !refRet["boss_born_area"].isNumber()
		|| !refRet["fresh_area"].isTable()
		|| !refRet["steal_money"].isTable()
		|| !refRet["fresh_mons"].isTable()
		)
	{
		LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg... lua parameter fields type error...valueLev:%d ", valueLev);
		return false;
	}
	luabridge::LuaRef refFreshArea = refRet["fresh_area"];
	int32_t area_len = refFreshArea.length();
	for (int32_t i = 1; i <= area_len; ++i)
	{
		uint32_t areaId = refFreshArea[i].cast<uint32_t>();
		const AreaAreaCfgInfo *pAreaCfg = g_GetAreaAreaCfgTable()->GetAreaAreaCfgInfo(areaId);
		if (nullptr == pAreaCfg)
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg...nullptr == pAreaCfg...areaid:%u, valueLev:%d ", areaId, valueLev);
			return false;
		}
		const AreaRefLocation *pAreaLoc = g_GetMapLocationCfg()->GetAreaRefLoc(pAreaCfg->belongToSceneID, areaId);
		if (nullptr == pAreaLoc)
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg...nullptr == pAreaLoc...mapid:%d, areaid:%d, valueLev:%d ", pAreaCfg->belongToSceneID, areaId, valueLev);
			return false;
		}
		cfg.setArea.insert(areaId);
	}
	luabridge::LuaRef refStealMoney = refRet["steal_money"];
	int32_t steal_len = refStealMoney.length();
	for (int32_t j = 1; j <= steal_len; ++j)
	{
		luabridge::LuaRef refInfo = refStealMoney[j];
		int32_t lev = refInfo["lev"].cast<int32_t>();
		GoblinStealMap::iterator iter = cfg.mapSteal.find(lev);
		if (iter == cfg.mapSteal.end())
		{
			GoblinStealCfg info;
			info.level = lev;
			info.maxMoney = refInfo["max_steal"].cast<int32_t>();
			info.minMoney = refInfo["min_steal"].cast<int32_t>();
			cfg.mapSteal[info.level] = info;
		}
		else
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg...already exists level:%d,valueLev:%d ", lev, valueLev);
		}
	}

	cfg.maxNpcNum = refRet["max_npc_num"].cast<int32_t>();
	cfg.curNpcNum = refRet["cur_npc_num"].cast<int32_t>();

	if (cfg.maxNpcNum < cfg.curNpcNum)
	{
		LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg.....cfg.maxNpcNum:%d < cfg.curNpcNum:%d , valueLev:%d ", cfg.maxNpcNum, cfg.curNpcNum, valueLev);
		return false;
	}
	if (cfg.curNpcNum > (int32_t)cfg.setArea.size())
	{
		LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg.....cfg.curNpcNum:%d  > (int32_t)cfg.setArea.size():%d, valueLev:%d ", cfg.curNpcNum, (int32_t)cfg.setArea.size(), valueLev);
		return false;
	}

	cfg.npcId = refRet["npc_id"].cast<uint32_t>();
	const NpcNpcCfgInfo *pNpcCfg = g_GetNpcNpcCfgTable()->GetNpcNpcCfgInfo(cfg.npcId);
	if (nullptr == pNpcCfg)
	{
		LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg....nullptr == pNpcCfg...npcid:%d,valueLev:%d ", cfg.npcId, valueLev);
		return false;
	}
	cfg.lifeSec = refRet["npc_life_sec"].cast<int32_t>();
	if (cfg.lifeSec <= 0)
	{
		LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg.....cfg.lifeSec <= 0... lifeSec:%d,valueLev:%d ", cfg.lifeSec, valueLev);
		return false;
	}
	cfg.bossMonsId = refRet["boss_id"].cast<uint32_t>();
	const MonsterMonsterCfgInfo *pMonsterCfg = g_GetMonsterMonsterCfgTable()->GetMonsterMonsterCfgInfo(cfg.bossMonsId);
	if (nullptr == pMonsterCfg)
	{
		LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg....nullptr == pMonsterCfg...bossMonsId:%d,valueLev:%d ", cfg.bossMonsId, valueLev);
		return false;
	}

	cfg.bornAreaId = refRet["boss_born_area"].cast<uint32_t>();
	const AreaAreaCfgInfo *pBossAreaCfg = g_GetAreaAreaCfgTable()->GetAreaAreaCfgInfo(cfg.bornAreaId);
	if (nullptr == pBossAreaCfg)
	{
		LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg...nullptr == pBossAreaCfg...areaid:%u, valueLev:%d ", cfg.bornAreaId, valueLev);
		return false;
	}
	const AreaRefLocation *pBossAreaLoc = g_GetMapLocationCfg()->GetAreaRefLoc(pBossAreaCfg->belongToSceneID, cfg.bornAreaId);
	if (nullptr == pBossAreaLoc)
	{
		LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg...nullptr == pBossAreaLoc...mapid:%d, areaid:%d, valueLev:%d ", pBossAreaCfg->belongToSceneID, cfg.bornAreaId, valueLev);
		return false;
	}

	luabridge::LuaRef refFreshMons = refRet["fresh_mons"];
	int32_t mons_len = refFreshMons.length();
	if (mons_len < 1)
	{
		LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg...fresh_mons ===  mons_len < 1...valueLev:%d ", mons_len, valueLev);
		return false;
	}
	for (int32_t k = 1; k <= mons_len; ++k)
	{
		luabridge::LuaRef refSingle = refFreshMons[k];
		if (!refSingle.isTable())
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg...fresh_mons === refSingle.isTable() return false...valueLev:%d ", valueLev);
			return false;
		}
		uint32_t monsId = refSingle["mons_id"].cast<uint32_t>();
		int32_t monsNum = refSingle["mons_num"].cast<int32_t>();
		const MonsterMonsterCfgInfo *pMonsterCfg = g_GetMonsterMonsterCfgTable()->GetMonsterMonsterCfgInfo(monsId);
		if (nullptr == pMonsterCfg)
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg..fresh_mons ===  nullptr == pMonsterCfg...monsid:%u, valueLev:%d ", monsId, valueLev);
			return false;
		}
		if (monsNum < 1)
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg..fresh_mons ===  monsNum < 1...monsNum:%d ,valueLev:%d ", monsNum, valueLev);
			return false;
		}
		MAP_UINT32_INT32::iterator iter = cfg.mapFreshMons.find(monsId);
		if (iter != cfg.mapFreshMons.end())
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetGoblinCfg..fresh_mons ===  repeated monster....monsId:%u, monsNum:%d,valueLev:%d  ", monsId, monsNum, valueLev);
		}
		cfg.mapFreshMons[monsId] = monsNum;
	}


	return true;
}
//获取远古精灵LUA配置
bool LogicActivityModule::LuaGetAncientElfCfg(AncientElfCfg &cfg,int32_t collegaLev)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	if (nullptr == pScript)
	{
		LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg... nullptr == pScript, collegaLev:%d ", collegaLev);
		return false;
	}
	luabridge::LuaRef refRet(pScript->GetState());
	if (!pScript->CallTableFuncRet("Activity", "LuaGetAncientElfCfg", refRet, collegaLev))
	{
		LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg... pScript->CallTableFuncRet return false...collegaLev:%d ", collegaLev);
		return false;
	}
	if (refRet.isNil())
	{
		LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg... refRet.isNil()...collegaLev:%d ", collegaLev);
		return false;
	}
	/*

	-- 暴躁的小精灵  mons_id:怪物ID,  max_num:最大数釿, cur_num:当前同时存在的数釿＿fresh_area：刷新的区域ID列表   每一组之间各自独立刷斿
	--  question_id：答题的题目ID列表, fresh_mons：触发刷怪的怪物ID
	['irritable_elf'] = { ['mons_id'] = 101, ['max_num'] = 20, ['cur_num'] = 10, ['fresh_area'] = {2001,2002} },
	-- 捣蛋的小精灵
	['trouble_elf'] =   { ['mons_id'] = 101, ['max_num'] = 20, ['cur_num'] = 10, ['fresh_area'] = {2001,2002} },
	-- 敏感的小精灵
	['sensitive_elf'] = { ['mons_id'] = 101, ['max_num'] = 20, ['cur_num'] = 10, ['fresh_area'] = {2001,2002} },
	-- 博学的小精灵
	['erudite_elf'] =   { ['npc_id'] = 201,  ['max_num'] = 20, ['cur_num'] = 10, ['fresh_area'] = {2001,2002},['question_id'] = {490100033,490100034} },
	-- 贪婪的小精灵
	['greed_elf'] = {
	['npc_id'] = 201,
	['max_num'] = 20,
	['cur_num'] = 10,
	-- NPC 出生的随机区域列衿
	['fresh_area'] = {2001,2002},
	-- 给予NPC金币数量
	['give_gold'] = 10,
	-- 触发刷怪的怪物ID,数量默认丿1, 刷在位面丿
	['fresh_mons'] = 3001
	}

	*/
	if (!refRet.isTable()
		|| !refRet["irritable_elf"].isTable()
		|| !refRet["trouble_elf"].isTable()
		|| !refRet["sensitive_elf"].isTable()
		|| !refRet["erudite_elf"].isTable()
		|| !refRet["greed_elf"].isTable()
		)
	{

		LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg... lua parameter fields type error...collegaLev:%d ", collegaLev);
		return false;
	}
	//暴躁的小精灵
	{
		luabridge::LuaRef refIrritable = refRet["irritable_elf"];
		cfg.irritableElf.cfgId = refIrritable["mons_id"].cast<uint32_t>();
		const MonsterMonsterCfgInfo *pMonsterCfg = g_GetMonsterMonsterCfgTable()->GetMonsterMonsterCfgInfo(cfg.irritableElf.cfgId);
		if (nullptr == pMonsterCfg)
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg....nullptr == pMonsterCfg...cfg.irritableElf.cfgId:%d, collegaLev:%d  ", cfg.irritableElf.cfgId, collegaLev);
			return false;
		}
		cfg.irritableElf.maxNum = refIrritable["max_num"].cast<int32_t>();
		cfg.irritableElf.curNum = refIrritable["cur_num"].cast<int32_t>();
		if (cfg.irritableElf.maxNum < cfg.irritableElf.curNum)
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg....cfg.irritableElf.maxNum:%d < cfg.irritableElf.curNum:%d, collegaLev:%d ", cfg.irritableElf.maxNum, cfg.irritableElf.curNum, collegaLev);
			return false;
		}
		if (!refIrritable["fresh_area"].isTable())
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg....irritable_elf fresh_area not table type collegaLev:%d ", collegaLev);
			return false;
		}
		luabridge::LuaRef refFreshArea = refIrritable["fresh_area"];
		int32_t area_len = refFreshArea.length();
		for (int32_t n = 1; n <= area_len; ++n)
		{
			
			uint32_t areaId = refFreshArea[n].cast<uint32_t>();
			const AreaAreaCfgInfo *pAreaCfg = g_GetAreaAreaCfgTable()->GetAreaAreaCfgInfo(areaId);
			if (nullptr == pAreaCfg)
			{
				LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...nullptr == pAreaCfg..irritable_elf  areaid:%u ,collegaLev:%d ", areaId, collegaLev);
				return false;
			}
			const AreaRefLocation *pAreaLoc = g_GetMapLocationCfg()->GetAreaRefLoc(pAreaCfg->belongToSceneID, areaId);
			if (nullptr == pAreaLoc)
			{
				LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...nullptr == pAreaLoc...mapid:%d, irritable_elf areaid:%d , collegaLev:%d ", pAreaCfg->belongToSceneID, areaId, collegaLev);
				return false;
			}
			cfg.irritableElf.setArea.insert(areaId);
		}

		if (cfg.irritableElf.curNum > (int32_t)cfg.irritableElf.setArea.size())
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...cfg.irritableElf.curNum > (int32_t)cfg.irritableElf.setArea.size() collegaLev:%d ", collegaLev);
			return false;
		}
	}


	//捣蛋小精灵
	{
		luabridge::LuaRef refTrouble = refRet["trouble_elf"];
		cfg.troubleElf.cfgId = refTrouble["mons_id"].cast<uint32_t>();
		const MonsterMonsterCfgInfo *pMonsterCfg = g_GetMonsterMonsterCfgTable()->GetMonsterMonsterCfgInfo(cfg.troubleElf.cfgId);
		if (nullptr == pMonsterCfg)
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg....nullptr == pMonsterCfg...cfg.trouble_elf.cfgId:%d , collegaLev:%d ", cfg.troubleElf.cfgId, collegaLev);
			return false;
		}
		cfg.troubleElf.maxNum = refTrouble["max_num"].cast<int32_t>();
		cfg.troubleElf.curNum = refTrouble["cur_num"].cast<int32_t>();
		if (cfg.troubleElf.maxNum < cfg.troubleElf.curNum)
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg....cfg.troubleElf.maxNum:%d < cfg.troubleElf.curNum:%d ,collegaLev:%d", cfg.troubleElf.maxNum, cfg.troubleElf.curNum, collegaLev);
			return false;
		}
		if (!refTrouble["fresh_area"].isTable())
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg....trouble_elf fresh_area not table type, collegaLev:%d ", collegaLev);
			return false;
		}
		luabridge::LuaRef refFreshArea = refTrouble["fresh_area"];
		int32_t area_len = refFreshArea.length();
		for (int32_t n = 1; n <= area_len; ++n)
		{
			uint32_t areaId = refFreshArea[n].cast<uint32_t>();
			const AreaAreaCfgInfo *pAreaCfg = g_GetAreaAreaCfgTable()->GetAreaAreaCfgInfo(areaId);
			if (nullptr == pAreaCfg)
			{
				LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...nullptr == pAreaCfg..trouble_elf  areaid:%u, collegaLev:%d ", areaId, collegaLev);
				return false;
			}
			const AreaRefLocation *pAreaLoc = g_GetMapLocationCfg()->GetAreaRefLoc(pAreaCfg->belongToSceneID, areaId);
			if (nullptr == pAreaLoc)
			{
				LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...nullptr == pAreaLoc...mapid:%d, trouble_elf areaid:%d ,collegaLev:%d ", pAreaCfg->belongToSceneID, areaId, collegaLev);
				return false;
			}
			cfg.troubleElf.setArea.insert(areaId);
		}

		if (cfg.troubleElf.curNum > (int32_t)cfg.troubleElf.setArea.size())
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...cfg.troubleElf.curNum > (int32_t)cfg.troubleElf.setArea.size()  collegaLev:%d ", collegaLev);
			return false;
		}
	}

	//敏感的小精灵
	{
		luabridge::LuaRef refSensitive = refRet["sensitive_elf"];
		cfg.sensitiveElf.cfgId = refSensitive["mons_id"].cast<uint32_t>();
		const MonsterMonsterCfgInfo *pMonsterCfg = g_GetMonsterMonsterCfgTable()->GetMonsterMonsterCfgInfo(cfg.sensitiveElf.cfgId);
		if (nullptr == pMonsterCfg)
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg....nullptr == pMonsterCfg...cfg.irritableElf.cfgId:%d, collegaLev:%d ", cfg.sensitiveElf.cfgId, collegaLev);
			return false;
		}
		cfg.sensitiveElf.maxNum = refSensitive["max_num"].cast<int32_t>();
		cfg.sensitiveElf.curNum = refSensitive["cur_num"].cast<int32_t>();
		if (cfg.sensitiveElf.maxNum < cfg.sensitiveElf.curNum)
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg....cfg.sensitive_elf.maxNum:%d < cfg.sensitive_elf.curNum:%d ,collegaLev:%d ", cfg.sensitiveElf.maxNum, cfg.sensitiveElf.curNum, collegaLev);
			return false;
		}
		if (!refSensitive["fresh_area"].isTable())
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg....sensitive_elf fresh_area is not table type collegaLev:%d ", collegaLev);
			return false;
		}
		luabridge::LuaRef refFreshArea = refSensitive["fresh_area"];
		int32_t area_len = refFreshArea.length();
		for (int32_t n = 1; n <= area_len; ++n)
		{
			uint32_t areaId = refFreshArea[n].cast<uint32_t>();
			const AreaAreaCfgInfo *pAreaCfg = g_GetAreaAreaCfgTable()->GetAreaAreaCfgInfo(areaId);
			if (nullptr == pAreaCfg)
			{
				LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...nullptr == pAreaCfg..sensitive_elf  areaid:%u ,collegaLev:%d ", areaId, collegaLev);
				return false;
			}
			const AreaRefLocation *pAreaLoc = g_GetMapLocationCfg()->GetAreaRefLoc(pAreaCfg->belongToSceneID, areaId);
			if (nullptr == pAreaLoc)
			{
				LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...nullptr == pAreaLoc...mapid:%d, sensitive_elf areaid:%d,collegaLev:%d ", pAreaCfg->belongToSceneID, areaId, collegaLev);
				return false;
			}
			cfg.sensitiveElf.setArea.insert(areaId);
		}

		if (cfg.sensitiveElf.curNum > (int32_t)cfg.sensitiveElf.setArea.size())
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...cfg.sensitiveElf.curNum > (int32_t)cfg.sensitiveElf.setArea.size(),collegaLev:%d ", collegaLev);
			return false;
		}
	}

	//博学的小精灵
	{
		luabridge::LuaRef refErudite = refRet["erudite_elf"];
		cfg.eruditeElf.cfgId = refErudite["npc_id"].cast<uint32_t>();
		const NpcNpcCfgInfo *pNpcCfg = g_GetNpcNpcCfgTable()->GetNpcNpcCfgInfo(cfg.eruditeElf.cfgId);
		if (nullptr == pNpcCfg)
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg....nullptr == pNpcCfg...cfg.erudite_elf.cfgId:%d,collegaLev:%d", cfg.eruditeElf.cfgId, collegaLev);
			return false;
		}
		cfg.eruditeElf.maxNum = refErudite["max_num"].cast<int32_t>();
		cfg.eruditeElf.curNum = refErudite["cur_num"].cast<int32_t>();
		if (cfg.eruditeElf.maxNum < cfg.eruditeElf.curNum)
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg....cfg.eruditeElf.maxNum:%d < cfg.eruditeElf.curNum:%d,collegaLev:%d ", cfg.eruditeElf.maxNum, cfg.eruditeElf.curNum, collegaLev);
			return false;
		}
		if (!refErudite["fresh_area"].isTable())
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg....erudite_elf fresh_area is not table type collegaLev:%d ", collegaLev);
			return false;
		}
		luabridge::LuaRef refFreshArea = refErudite["fresh_area"];
		int32_t area_len = refFreshArea.length();
		for (int32_t n = 1; n <= area_len; ++n)
		{
			uint32_t areaId = refFreshArea[n].cast<uint32_t>();
			const AreaAreaCfgInfo *pAreaCfg = g_GetAreaAreaCfgTable()->GetAreaAreaCfgInfo(areaId);
			if (nullptr == pAreaCfg)
			{
				LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...nullptr == pAreaCfg..eruditeElf  areaid:%u collegaLev:%d ", areaId, collegaLev);
				return false;
			}
			const AreaRefLocation *pAreaLoc = g_GetMapLocationCfg()->GetAreaRefLoc(pAreaCfg->belongToSceneID, areaId);
			if (nullptr == pAreaLoc)
			{
				LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...nullptr == pAreaLoc...mapid:%d, eruditeElf areaid:%d , collegaLev:%d ", pAreaCfg->belongToSceneID, areaId, collegaLev);
				return false;
			}
			cfg.eruditeElf.setArea.insert(areaId);
		}

		if (!refErudite["question_id"].isTable())
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg....erudite_elf question_id is not table type collegaLev:%d ", collegaLev);
			return false;
		}
		luabridge::LuaRef refQuestion = refErudite["question_id"];
		int32_t question_len = refQuestion.length();
		for (int32_t m = 1; m <= question_len; m++)
		{
			uint32_t questid = refQuestion[m].cast<uint32_t>();
			const AnswerAnswerCfgInfo *pAnswerCfg = g_GetAnswerAnswerCfgTable()->GetAnswerAnswerCfgInfo(questid);
			if (nullptr == pAnswerCfg)
			{
				LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...nullptr == pAnswerCfg..eruditeElf  questid:%u ,collegaLev:%d ", questid, collegaLev);
				return false;
			}
			cfg.eruditeElf.setQuestion.insert(questid);
		}

		if (cfg.eruditeElf.curNum > (int32_t)cfg.eruditeElf.setArea.size())
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...cfg.sensitiveElf.curNum > (int32_t)cfg.sensitiveElf.setArea.size() collegaLev:%d ", collegaLev);
			return false;
		}
	}


	//贪婪的小精灵
	{
		luabridge::LuaRef refGreed = refRet["greed_elf"];
		cfg.greedElf.cfgId = refGreed["npc_id"].cast<uint32_t>();
		const NpcNpcCfgInfo *pNpcCfg = g_GetNpcNpcCfgTable()->GetNpcNpcCfgInfo(cfg.eruditeElf.cfgId);
		if (nullptr == pNpcCfg)
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg....nullptr == pNpcCfg...cfg.greedElf.cfgId:%d,collegaLev:%d ", cfg.greedElf.cfgId, collegaLev);
			return false;
		}
		cfg.greedElf.maxNum = refGreed["max_num"].cast<int32_t>();
		cfg.greedElf.curNum = refGreed["cur_num"].cast<int32_t>();
		if (cfg.greedElf.maxNum < cfg.eruditeElf.curNum)
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg....cfg.greedElf.maxNum:%d < cfg.greedElf.curNum:%d ,collegaLev:%d ", cfg.greedElf.maxNum, cfg.greedElf.curNum, collegaLev);
			return false;
		}
		if (!refGreed["fresh_area"].isTable())
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg....greed_elf fresh_area is not table type collegaLev:%d ", collegaLev);
			return false;
		}
		luabridge::LuaRef refFreshArea = refGreed["fresh_area"];
		int32_t area_len = refFreshArea.length();
		for (int32_t n = 1; n <= area_len; ++n)
		{
			uint32_t areaId = refFreshArea[n].cast<uint32_t>();
			const AreaAreaCfgInfo *pAreaCfg = g_GetAreaAreaCfgTable()->GetAreaAreaCfgInfo(areaId);
			if (nullptr == pAreaCfg)
			{
				LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...nullptr == pAreaCfg..greedElf  areaid:%u,collegaLev:%d ", areaId, collegaLev);
				return false;
			}
			const AreaRefLocation *pAreaLoc = g_GetMapLocationCfg()->GetAreaRefLoc(pAreaCfg->belongToSceneID, areaId);
			if (nullptr == pAreaLoc)
			{
				LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...nullptr == pAreaLoc...mapid:%d, greedElf areaid:%d collegaLev:%d ", pAreaCfg->belongToSceneID, areaId, collegaLev);
				return false;
			}
			cfg.greedElf.setArea.insert(areaId);
		}

		cfg.greedElf.freshMonsId = refGreed["fresh_mons"].cast<uint32_t>();
		const MonsterMonsterCfgInfo *pMonsterCfg = g_GetMonsterMonsterCfgTable()->GetMonsterMonsterCfgInfo(cfg.greedElf.freshMonsId);
		if (nullptr == pMonsterCfg)
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...nullptr == pMonsterCfg..cfg.greedElf.freshMonsId:%d, collegaLev:%d ", cfg.greedElf.freshMonsId, collegaLev);
			return false;
		}

		cfg.greedElf.giveGold = refGreed["give_gold"].cast<int32_t>();
		luabridge::LuaRef refGiveGoldReward = refGreed["give_gold_reward"];
		if (!refGiveGoldReward.isTable())
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...refGiveGoldReward.isTable() collegaLev:%d ", collegaLev);
			return false;
		}
		int32_t rewardlen = refGiveGoldReward.length();
		for (int32_t m = 1; m <= rewardlen; ++m)
		{
			luabridge::LuaRef refReward = refGiveGoldReward[m];
			if (!refReward.isTable())
			{
				LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...refReward.isTable() collegaLev:%d ", collegaLev);
				return false;
			}
			GiveRewardCfg reward;
			reward.itemId = refReward["item_id"].cast<uint32_t>();
			reward.minNum = refReward["min_num"].cast<int32_t>();
			reward.maxNum = refReward["max_num"].cast<int32_t>();
			reward.rate = refReward["rate"].cast<int32_t>();
			if (reward.minNum <= 0 || reward.maxNum <= 0)
			{
				LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...reward.minNum <= 0 || reward.maxNum <= 0, itemid:%u, minnum:%d, maxnum:%d ,collegaLev:%d ", reward.itemId, reward.minNum, reward.maxNum, collegaLev);
				return false;
			}
			const ItemItemCfgInfo *pItemCfg = g_GetItemItemCfgTable()->GetItemItemCfgInfo(reward.itemId);
			if (nullptr == pItemCfg)
			{
				const EquipEquipCfgInfo *pEquipCfg = g_GetEquipEquipCfgTable()->GetEquipEquipCfgInfo(reward.itemId);
				if (nullptr == pEquipCfg)
				{
					LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...nullptr == pEquipCfg, itemid:%u ,collegaLev:%d ", reward.itemId, collegaLev);
					return false;
				}
			}
			cfg.greedElf.vecGiveReward.push_back(reward);
		}

		if (cfg.greedElf.curNum > (int32_t)cfg.greedElf.setArea.size())
		{
			LogErrFmtPrint("[logic] LogicActivityModule::LuaGetAncientElfCfg...cfg.greedElf.curNum > (int32_t)cfg.greedElf.setArea.size()  collegaLev:%d ", collegaLev);
			return false;
		}

	}

	return true;
}


//获取远古精灵答题正确之后的奖励
void LogicActivityModule::GetEruditeElfReward(int32_t level,int32_t &gold, int32_t &unionContri)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	if (nullptr == pScript)
	{
		LogErrFmtPrint("[logic] LogicActivityModule::GetEruditeElfReward... nullptr == pScript");
		return;
	}
	luabridge::LuaRef refRet(pScript->GetState());
	if (!pScript->CallTableFuncRet("Activity", "EruditeElfReward", refRet,level))
	{
		LogErrFmtPrint("[logic] LogicActivityModule::GetEruditeElfReward... pScript->CallTableFuncRet return false...");
		return;
	}
	if (!refRet.isTable())
	{
		LogErrFmtPrint("[logic] LogicActivityModule::GetEruditeElfReward... !refRet.isTable() return false...");
		return;
	}
	gold = refRet["gold"].cast<int32_t>();
	unionContri = refRet["union_contri"].cast<int32_t>();
}

//怪物攻城LUA配置
bool LogicActivityModule::LuaGetMonsAttackCity(MonsAttackCityCfg &cfg)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	if (nullptr == pScript)
	{
		MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity... nullptr == pScript");
		return false;
	}
	luabridge::LuaRef refRet(pScript->GetState());
	if (!pScript->CallTableFuncRet("Activity", "GetMonsAttackCity", refRet))
	{
		MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity... pScript->CallTableFuncRet return false...");
		return false;
	}
	if (!refRet.isTable())
	{
		MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity... !refRet.isTable() return false...");
		return false;
	}
	/*
	--根据前100平均等级 向上取的等级
	['ceil_level'] = 5,
	--根据前100平均等级 向下取的等级
	['floor_level'] = 14,
	--刷新怪物最低等级
	['mons_min_level'] = 20,
	--怪物总波数
	['mons_total_wave'] = 240,
	--每一大波怪刷新间隔,单位：秒
	['wave_inter'] = 30,

	-- 水晶怪
	['crystal_mons'] = {
	-- mons_id:怪物ID, area_id:出生区域
	{ ['mons_id'] = 101, ['area_id'] = 1001 },
	{ ['mons_id'] = 102, ['area_id'] = 1001 },
	{ ['mons_id'] = 103, ['area_id'] = 1001 },
	{ ['mons_id'] = 104, ['area_id'] = 1001 }
	},

	--区域路径,每次刷怪所有的区域内同时刷新 当前等级的怪
	['area_line'] = {
	{ ['area_id'] = 370180402,['line_id'] = 370280402  },
	{ ['area_id'] = 370180402,['line_id'] = 370280402  },
	{ ['area_id'] = 370180402,['line_id'] = 370280402  }
	},


	-- 宝箱怪，活动结束时刷新
	['box_mons'] = {
	-- 剩余水晶怪数量
	[1] = {



	-- 攻城怪物,所有区域在每个等级都对应刷新的怪，每个等级都是 先刷完小怪，再刷新boss
	['attack_mons'] = {

	-- 等级对应刷新的怪
	[20] = {
	--怪物ID列表
	['mons_id'] = {220120401,220120402,220120403},
	--怪物总数量
	*/
	if (!refRet["take_effect_day"].isNumber()
		|| !refRet["ceil_level"].isNumber()
		|| !refRet["floor_level"].isNumber()
		|| !refRet["mons_min_level"].isNumber()
		|| !refRet["mons_total_wave"].isNumber()
		|| !refRet["wave_inter"].isNumber()
		|| !refRet["crystal_mons"].isTable()
		|| !refRet["area_line"].isTable()
		|| !refRet["box_mons"].isTable()
		|| !refRet["attack_mons"].isTable()
		)
	{
		MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity... lua format error... return false...");
		return false;
	}
	cfg.effectDay = refRet["take_effect_day"].cast<int32_t>();
	cfg.ceilLev = refRet["ceil_level"].cast<int32_t>();
	cfg.floorLev = refRet["floor_level"].cast<int32_t>();
	cfg.monsMinLev = refRet["mons_min_level"].cast<int32_t>();
	cfg.totalWave = refRet["mons_total_wave"].cast<int32_t>();
	cfg.waveSec = refRet["wave_inter"].cast<int32_t>();
	//
	luabridge::LuaRef refCrystalMons = refRet["crystal_mons"];
	int32_t crystallen = refCrystalMons.length();
	for (int32_t i = 1; i <= crystallen; ++i)
	{
		/*
			['crystal_mons'] = {
			-- mons_id:怪物ID, area_id:出生区域
			{ ['mons_id'] = 101, ['area_id'] = 1001 },
			{ ['mons_id'] = 102, ['area_id'] = 1001 },
			{ ['mons_id'] = 103, ['area_id'] = 1001 },
			{ ['mons_id'] = 104, ['area_id'] = 1001 }
			},
		*/
		luabridge::LuaRef refSingle = refCrystalMons[i];
		uint32_t monsId = refSingle["mons_id"].cast<uint32_t>();
		uint32_t areaId = refSingle["area_id"].cast<uint32_t>();
		const MonsterMonsterCfgInfo *pMonsCfg = g_GetMonsterMonsterCfgTable()->GetMonsterMonsterCfgInfo(monsId);
		if (nullptr == pMonsCfg)
		{
			MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity... nullptr == pMonsCfg 11...monsId:%u ", monsId);
			return false;
		}
		const AreaAreaCfgInfo *pAreaCfg = g_GetAreaAreaCfgTable()->GetAreaAreaCfgInfo(areaId);
		if (nullptr == pAreaCfg)
		{
			MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity... nullptr == pAreaCfg 11...monsId:%u, areaid:%u ", monsId, areaId);
			return false;
		}
		AttackMonsSingleCfgInfo info;
		info.monsId = monsId;
		info.areaId = areaId;
		cfg.vecCrystal.push_back(info);
	}
	//
	luabridge::LuaRef refPointMons = refRet["point_mons"];
	int32_t pointlen = refPointMons.length();
	for (int32_t h = 1; h <= pointlen; ++h)
	{
		/*
		{ ['mons_id'] = 220199823,['posX'] = 387.38,['posY'] = 202.70,['posZ'] = 135.46 },
		{ ['mons_id'] = 220199824,['posX'] = 636.39,['posY'] = 202.70,['posZ'] = 135.46 }
		*/
		PointMonsCfgInfo info;
		luabridge::LuaRef refSingle = refPointMons[h];
		info.monsId = refSingle["mons_id"].cast<uint32_t>();
		info.fx = refSingle["x"].cast<float>();
		info.fy = refSingle["y"].cast<float>();
		info.fz = refSingle["z"].cast<float>();
		const MonsterMonsterCfgInfo *pMonsCfg = g_GetMonsterMonsterCfgTable()->GetMonsterMonsterCfgInfo(info.monsId);
		if (nullptr == pMonsCfg)
		{
			MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity... nullptr == pMonsCfg 55...monsId:%u ", info.monsId);
			return false;
		}
		cfg.vecPointMons.push_back(info);
	}
	//
	luabridge::LuaRef refAreaLine = refRet["area_line"];
	int32_t arealinelen = refAreaLine.length();
	for (int32_t j = 1; j <= arealinelen; ++j)
	{
		/*
		--区域路径,每次刷怪所有的区域内同时刷新 当前等级的怪
		['area_line'] = {
		{ ['area_id'] = 370180402,['line_id'] = 370280402  },
		{ ['area_id'] = 370180402,['line_id'] = 370280402  },
		{ ['area_id'] = 370180402,['line_id'] = 370280402  }
		},
		*/
		luabridge::LuaRef refSingle = refAreaLine[j];
		if (!refSingle["area_id"].isNumber()
			|| !refSingle["line_id"].isNumber()
			)
		{
			MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity...lua format error 22...");
			return false;
		}
		uint32_t areaId = refSingle["area_id"].cast<uint32_t>();
		uint32_t lineId = refSingle["line_id"].cast<uint32_t>();
		const AreaAreaCfgInfo *pAreaCfg = g_GetAreaAreaCfgTable()->GetAreaAreaCfgInfo(areaId);
		if (nullptr == pAreaCfg)
		{
			MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity... nullptr == pAreaCfg 22...areaid:%u ", areaId);
			return false;
		}
		const AreaPathCfgInfo *pPathCfg = g_GetAreaPathCfgTable()->GetAreaPathCfgInfo(lineId);
		if (nullptr == pPathCfg)
		{
			MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity....nullptr == pPathCfg...pathid:%u, ", lineId);
			return false;
		}
		if (pPathCfg->belongToSceneID != (int32_t)pAreaCfg->belongToSceneID)
		{
			MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity...pPathCfg->belongToSceneID != (int32_t)pAreaCfg->belongToSceneID..pathid:%u, belongToSceneID:%u, mapid:%u ", lineId, pPathCfg->belongToSceneID, pAreaCfg->belongToSceneID);
			return false;
		}
		const PathRefLocation *pPathLoc = g_GetMapLocationCfg()->GetPathRefLoc(lineId);
		if (nullptr == pPathLoc)
		{
			MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity..nullptr == pPathLoc....  mapid:%u, areaid:%u, lineid:%d  ", pAreaCfg->belongToSceneID,areaId,lineId);
			return false;
		}

		MAP_UINT32_UINT32::iterator iter = cfg.mapAreaLine.find(areaId);
		if (iter != cfg.mapAreaLine.end())
		{
			MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity...iter != cfg.mapAreaLine.end()..areaid:%u,lineid:%u ",areaId, lineId);
			return false;
		}

		cfg.mapAreaLine[areaId] = lineId;
	}

	//
	luabridge::LuaRef refBoxMons = refRet["box_mons"];
	int32_t boxmonsLen = refBoxMons.length();
	for (int32_t m = 1; m <= boxmonsLen; ++m)
	{
		/*
				-- 宝箱怪，活动结束时刷新
				['box_mons'] = {
				{
				-- 宝箱怪
				{ ['mons_id'] = 220120401, ['num'] = 3,['area_id'] = 370180402 },
				{ ['mons_id'] = 220120401, ['num'] = 3,['area_id'] = 370180402 },
				{ ['mons_id'] = 220120401, ['num'] = 3,['area_id'] = 370180402 }
				},
				{
				{ ['mons_id'] = 220120401, ['num'] = 3,['area_id'] = 370180402 },
				{ ['mons_id'] = 220120401, ['num'] = 3,['area_id'] = 370180402 },
				{ ['mons_id'] = 220120401, ['num'] = 3,['area_id'] = 370180402 }
				},
				{
				{ ['mons_id'] = 220120401, ['num'] = 3,['area_id'] = 370180402 },
				{ ['mons_id'] = 220120401, ['num'] = 3,['area_id'] = 370180402 },
				{ ['mons_id'] = 220120401, ['num'] = 3,['area_id'] = 370180402 }
				},
				{
				{ ['mons_id'] = 220120401, ['num'] = 3,['area_id'] = 370180402 },
				{ ['mons_id'] = 220120401, ['num'] = 3,['area_id'] = 370180402 },
				{ ['mons_id'] = 220120401, ['num'] = 3,['area_id'] = 370180402 }
				}

				},
		*/
		VecAttackMonsSingle vecMons;
		vecMons.clear();
		luabridge::LuaRef refSingle = refBoxMons[m];
		int32_t monslen = refSingle.length();
		for (int32_t n = 1; n <= monslen; ++n)
		{
			luabridge::LuaRef refSingleEx = refSingle[n];

			if (!refSingleEx["mons_id"].isNumber()
				|| !refSingleEx["num"].isNumber()
				|| !refSingleEx["area_id"].isNumber()
				)
			{
				MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity...lua format error 33...m:%d,n:%d ",m,n);
				return false;
			}

			uint32_t monsId = refSingleEx["mons_id"].cast<uint32_t>();
			uint32_t monsNum = refSingleEx["num"].cast<uint32_t>();
			uint32_t areaId = refSingleEx["area_id"].cast<uint32_t>();
			//
			const MonsterMonsterCfgInfo *pMonsCfg = g_GetMonsterMonsterCfgTable()->GetMonsterMonsterCfgInfo(monsId);
			if (nullptr == pMonsCfg)
			{
				MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity... nullptr == pMonsCfg 33...monsId:%u,m:%d,n:%d ", monsId,m,n);
				return false;
			}
			const AreaAreaCfgInfo *pAreaCfg = g_GetAreaAreaCfgTable()->GetAreaAreaCfgInfo(areaId);
			if (nullptr == pAreaCfg)
			{
				MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity... nullptr == pAreaCfg 33...areaid:%u,m:%d,n:%d ", areaId,m,n);
				return false;
			}
			if (monsNum <= 0)
			{
				MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity... monsNum <= 0 33...monsid:%u, areaid:%u,m:%d,n:%d ", monsId, areaId,m,n);
				return false;
			}
			AttackMonsSingleCfgInfo info;
			info.monsId = monsId;
			info.areaId = areaId;
			info.monsNum = monsNum;
			vecMons.push_back(info);
		}
		if (vecMons.size() > 0)
		{
			cfg.mapBoxMons[m] = vecMons;
		}
	}

	//
	luabridge::LuaRef refAttackMons = refRet["attack_mons"];
	int32_t attacklen = refAttackMons.length();
	for (int32_t k = 1; k <= attacklen; ++k)
	{
		/*
		 {
		 ['mons_level'] = 20,
		 --怪物ID列表
		 ['mons_id'] = {220198001,220198002,220198003},
		 --怪物总数量
		 ['mons_total_num'] = 30,
		 --每次刷新怪物数量
		 ['mons_per_num'] = 6,
		 -- 怪物刷新每次刷新间隔,单位：秒
		 ['mons_per_sec'] = 4,


		 -- boss和大 boss是可选的
		 -- boss id列表（先刷完小怪，再刷新boss）
		 ['boss_id'] = {220198801},
		 -- boss 总数量
		 ['boss_total_num'] = 1,
		 -- 每次刷新的boss数量
		 ['boss_per_num'] = 1,
		 -- boss 每次刷新的间隔,单位：秒
		 ['boss_per_inter'] = 1,

		 --每个等级段最后一个大boss
		 ['big_boss_id'] = 220198809,
		 --每个等级段最后一波刷完之后,间隔多久再刷新大boss 单位：秒
		 ['big_boss_inter'] = 5
		 },
		*/
		luabridge::LuaRef refSingle = refAttackMons[k];
		if (!refSingle["mons_level"].isNumber()
			|| !refSingle["mons_id"].isTable()
			|| !refSingle["mons_total_num"].isNumber()
			|| !refSingle["mons_per_num"].isNumber()
			|| !refSingle["mons_per_sec"].isNumber()
			/*|| !refSingle["boss_id"].isTable()
			|| !refSingle["boss_total_num"].isNumber()
			|| !refSingle["boss_per_num"].isNumber()
			|| !refSingle["boss_per_inter"].isNumber()*/
			)
		{
			MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity...lua format error 44...");
			return false;
		}
		int32_t monsLev = refSingle["mons_level"].cast<int32_t>();
		AttackMonsCfgInfo info;
		info.monsMinLevel = monsLev;
		info.totalMonsNum = refSingle["mons_total_num"].cast<int32_t>();
		info.perMonsNum = refSingle["mons_per_num"].cast<int32_t>();
		info.perMonsSec = refSingle["mons_per_sec"].cast<int32_t>();

		luabridge::LuaRef refSingleMons = refSingle["mons_id"];
		int32_t monlen = refSingleMons.length();
		for (int32_t h = 1; h <= monlen; ++h)
		{
			uint32_t monsId = refSingleMons[h];
			const MonsterMonsterCfgInfo *pMonsCfg = g_GetMonsterMonsterCfgTable()->GetMonsterMonsterCfgInfo(monsId);
			if (nullptr == pMonsCfg)
			{
				MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity... nullptr == pMonsCfg 44...monsId:%u, k:%d,h:%d ", monsId,k,h);
				return false;
			}
			info.setMons.insert(monsId);
		}


		//boss和大boss是可选的，只要存在其中一个字段，所有的字段必须都存在，或者所有的boss字段都不存在
		if (refSingle["boss_id"].isTable()
			|| refSingle["boss_total_num"].isNumber()
			|| refSingle["boss_per_num"].isNumber()
			|| refSingle["boss_per_inter"].isNumber())
		{
			if (!refSingle["boss_id"].isTable()
				|| !refSingle["boss_total_num"].isNumber()
				|| !refSingle["boss_per_num"].isNumber()
				|| !refSingle["boss_per_inter"].isNumber()
				)
			{
				MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity...lua format error boss 44...");
				return false;
			}
			info.totalBossNum = refSingle["boss_total_num"].cast<int32_t>();
			info.perBossNum = refSingle["boss_per_num"].cast<int32_t>();
			info.perBossSec = refSingle["boss_per_inter"].cast<int32_t>();

			luabridge::LuaRef refSingleBoss = refSingle["boss_id"];
			int32_t bosslen = refSingleBoss.length();
			for (int32_t a = 1; a <= bosslen; ++a)
			{
				uint32_t bossId = refSingleBoss[a];
				const MonsterMonsterCfgInfo *pMonsCfg = g_GetMonsterMonsterCfgTable()->GetMonsterMonsterCfgInfo(bossId);
				if (nullptr == pMonsCfg)
				{
					MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity... nullptr == pMonsCfg 44...bossId:%u,k:%d,a:%d ", bossId, k, a);
					return false;
				}
				info.setBoss.insert(bossId);
			}

			if (info.setMons.size() < 1)
			{
				MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity... info.setMons.size() < 1 44...monsLev:%d,k:%d ", monsLev, k);
				return false;
			}
			AttackMonsCfgMap::iterator iterLev = cfg.mapAttackMons.find(monsLev);
			if (iterLev != cfg.mapAttackMons.end())
			{
				MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity... iterLev != cfg.mapAttackMons.end()  44...monsLev:%d,k:%d ", monsLev, k);
				return false;
			}

		}

		if (refSingle["big_boss_id"].isNumber()
			|| refSingle["big_boss_inter"].isNumber()
			)
		{
			if (!refSingle["big_boss_id"].isNumber()
				|| !refSingle["big_boss_inter"].isNumber()
				)
			{
				MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity...lua format error big boss 44...");
				return false;
			}
			info.totalBigBossNum = 1;//默认只有一个
			info.bigBossId = refSingle["big_boss_id"].cast<uint32_t>();
			info.perBigBossSec = refSingle["big_boss_inter"].cast<int32_t>();
			const MonsterMonsterCfgInfo *pBigBossMonsCfg = g_GetMonsterMonsterCfgTable()->GetMonsterMonsterCfgInfo(info.bigBossId);
			if (nullptr == pBigBossMonsCfg)
			{
				MMOLOG_FMT_ERROR("[logic] LogicActivityModule::LuaGetMonsAttackCity... nullptr == pBigBossMonsCfg 44...bossId:%u,k:%d ", info.bigBossId, k);
				return false;
			}
		}		
		//
		cfg.mapAttackMons[monsLev] = info;
	}

	return true;
}


GActivity* LogicActivityModule::MutStaticActivity(uint32_t activityId)
{
	GActivity* pActivity = MakeActivityObj(activityId);
	if (nullptr != pActivity)
	{
		m_mapActivity[activityId] = pActivity;
	}

	return pActivity;
}

GActivity* LogicActivityModule::FindStaticActivity(uint32_t activityId)
{
	StaticActivityMap::iterator iter = m_mapActivity.find(activityId);
	if (iter != m_mapActivity.end())
	{
		return iter->second;
	}

	return nullptr;
}

void LogicActivityModule::UpdateActivity()
{
	StaticActivityMap::iterator iter = m_mapActivity.begin();
	for (; iter != m_mapActivity.end(); ++iter)
	{
		if (nullptr != iter->second && iter->second->IsRuning())
		{
			iter->second->Update();
		}
	}
}

void LogicActivityModule::CloseStaticActivity(uint32_t activityId)
{
	StaticActivityMap::iterator iter = m_mapActivity.find(activityId);
	if (iter != m_mapActivity.end())
	{
		if (nullptr != iter->second && iter->second->IsRuning())
		{
			iter->second->StopActivity();
		}
	}
}

bool LogicActivityModule::IsRunning(uint32_t actId)
{
	const ActData *pActData = GetActData(actId);
	if (nullptr == pActData)
	{
		return false;
	}
	return pActData->state;
}

bool LogicActivityModule::IsRunningByType(ACTIVITY_TYPE_ID enType)
{
	uint32_t actId = 0;
	const ActivityDailyCfgMap * pMap=g_GetActivityDailyCfgTable()->GetActivityDailyCfgMap();
	for (ActivityDailyCfgMap::const_iterator iter = pMap->begin(); iter != pMap->end();++iter)
	{
		if (iter->second.typeId == (int)enType )
		{
			actId = iter->first;
			break;
		}
	}
	return IsRunning(actId);
}

//时间是否再指定活动期间
bool LogicActivityModule::IsDuringAct(uint32_t actId, uint64_t lastTime)
{
	const ActData *pActData = GetActData(actId);
	if (nullptr == pActData)
	{
		return false;
	}
	if (!pActData->state)
	{
		return false;
	}
	if (lastTime < pActData->beginTime || lastTime > pActData->endTime)
	{
		return false;
	}
	return true;
}


const ActData*LogicActivityModule::GetActData(uint32_t actId)
{
	ActDataMap::iterator iter = m_mapActivityData.find(actId);
	return (iter != m_mapActivityData.end()) ? &iter->second : nullptr;
}

void LogicActivityModule::NotifyAddTrack(SET_UINT64 &setPlayer, int8_t type, MultiTrackProto &trackProto)	//增加哥布林追踪数据
{
	CGOperateLimitAddStageRsp rsp;
	rsp.set_type(type);
	MultiTrackProto *proto = rsp.mutable_track();
	if (nullptr != proto)
	{
		proto->CopyFrom(trackProto);
	}
	SET_UINT64::iterator iter = setPlayer.begin();
	for (; iter != setPlayer.end(); ++iter)
	{
		g_GetLogicService()->SendDataToClient((*iter),EMODULE_ID_OPERATELIMIT, LOGIC_TO_CLIENT_OPERATELIMIT_ADD_STAGE, &rsp);
	}
}


void LogicActivityModule::NotifyUpdateTrack(SET_UINT64 &setPlayer, int8_t type, MultiTrackProto &trackProto) 	//更新哥布林追踪数据
{
	CGOperateLimitStageUpdateRsp rsp;
	rsp.set_type(type);
	MultiTrackProto *proto = rsp.mutable_track();
	if (nullptr != proto)
	{
		proto->CopyFrom(trackProto);
	}
	SET_UINT64::iterator iter = setPlayer.begin();
	for (; iter != setPlayer.end(); ++iter)
	{
		g_GetLogicService()->SendDataToClient((*iter), EMODULE_ID_OPERATELIMIT, LOGIC_TO_CLIENT_OPERATELIMIT_UPDATE_STAGE, &rsp);
	}
}

//通知移除追踪数据
void LogicActivityModule::NotifyDelTrack(SET_UINT64 &setPlayer,int8_t type)
{
	CGOperateLimitStageDelRsp rsp;
	rsp.set_type(type);
	SET_UINT64::iterator iter = setPlayer.begin();
	for (; iter != setPlayer.end(); ++iter)
	{
		g_GetLogicService()->SendDataToClient((*iter), EMODULE_ID_OPERATELIMIT, LOGIC_TO_CLIENT_OPERATELIMIT_DEL_STAGE, &rsp);
	}
}

bool LogicActivityModule::OnGetAnswerInfo(CharIDType charID, RECV_PACKAGE &package)
{
	ActivityAnswerInfoReq req;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		LogErrFmtPrint("[center] LogicActivityModule::EnterActivityReq prase failed...");
		return false;
	}

	if (req.activetype() == enActiveAnswerType_World)
	{
		OnGetWorldAnswerInfo(charID, req);
	}
	else
	{
		OnGetDailyAnswerInfo(charID,req);
	}
	return true;
}
bool LogicActivityModule::OnAnswerResult(CharIDType charID, RECV_PACKAGE &package)
{

	ActivityAnswerResultReq req;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		LogErrFmtPrint("[center] LogicActivityModule::EnterActivityReq prase failed...");
		return false;
	}

	if (req.activetype() == enActiveAnswerType_World)
	{
		OnWorldAnswerResult(charID, req);
	}
	else
	{
		OnDailyAnswerResult(charID, req);
	}
	return true;
}
bool LogicActivityModule::OnAnswerGetLastReward(CharIDType charID, RECV_PACKAGE &package)
{
	ActivityAnswerGetLastRewardReq req;
	if (!req.ParseFromArray(package.dataAfterHead, package.sizeAfterHead))
	{
		LogErrFmtPrint("[center] LogicActivityModule::EnterActivityReq prase failed...");
		return false;
	}

	if (req.activetype() == enActiveAnswerType_World)
	{
		OnWorldAnswerGetLastReward(charID, req);
	}
	else
	{
		OnDailyAnswerGetLastReward(charID, req);
	}
	return true;
}

//世界答题活动，答正确一题给的奖励
bool LogicActivityModule::RewardActiveAnswerOneSucceed(Player *pPlayer)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	if (nullptr == pScript)
	{
		LogErrFmtPrint("[center] LogicActivityModule::RewardActiveAnswerOneSucceed....nullptr == pScript... ");
		return 0;
	}
	LuaRef ref(pScript->GetState());
	if (!pScript->CallTableFuncRet("Activity", "GetAnswerBoxReward", ref))
	{
		LogErrFmtPrint("[center] LogicActivityModule::RewardActiveAnswerOneSucceed...pScript->CallTableFuncRet failed....");
		return 0;
	}
	if (!ref.isTable())
	{
		LogErrFmtPrint("[center] LogicActivityModule::RewardActiveAnswerOneSucceed...!ref.isTable() return false....");
		return 0;
	}

	int32_t boxid = ref["box_id"].cast<uint32_t>();;
	uint32_t rate = ref["rate"].cast<int32_t>();

	if (Random(0,100)<rate)
	{
		//发放奖励
		VEC_INT32 vecBox;
		vecBox.push_back(boxid);
		SItemSourceParam sourceParam;
		sourceParam.notifySource = ENotifyType_Item_WorldAnswer;
		sourceParam.notifyVal = g_GetDuplicateCfgMgr()->GetWorldAnswerActId();
		if (g_GetDropMgr()->PlayerAddBox(pPlayer, vecBox, sourceParam) != RET_SUCCESS)
		{
			std::vector<ItemProtoInfo> vecProto;
			int32_t gold, bindnum, diamnum;
			BoxCondCfg boncfg;
			g_GetDropMgr()->GetBoxCond(pPlayer, boncfg);
			g_GetItemMgr()->CreateBoxDropItem(boxid, vecProto, gold, diamnum, bindnum, boncfg);
			//发放邮件
			string strTopic = "世界答题";
			string strContent = "你在世界答题活动中，回答正确，获得物品！";
			g_GetGMailMgr()->SendSystemMail(pPlayer->GetId(), strTopic, strContent, 0, 0, 0, 0, 0, vecProto);
		}

		LogDebugFmtPrint("LogicActivityModule::RewardActiveAnswerOneSucceed boxid=%d",boxid);
	}

	return true;
}
//添加活动(此接口用于再逻辑服没有创建活动对象的情况）
void LogicActivityModule::OnAttendActivity(uint32_t activityId, CharIDType cid)
{
	AttendActEvent attendEvent;
	attendEvent.activityId = activityId;
	attendEvent.cid = cid;
	g_GetEvent()->FireExecute(EVENT_ATTEND_ACTIVITY, cid,CREATURE_PLAYER, &attendEvent, sizeof(AttendActEvent));
}
//完成活动(此接口用于再逻辑服没有创建活动对象的活动)
void LogicActivityModule::OnFinishActivity(uint32_t activityId,CharIDType cid)
{
	FinishActEvent finishEvent;
	finishEvent.activityId = activityId;
	finishEvent.cid = cid;
	g_GetEvent()->FireExecute(EVENT_FINISH_ACTIVITY, cid, CREATURE_PLAYER, &finishEvent, sizeof(FinishActEvent));
}

//接取活动收集任务
void LogicActivityModule::OnAcceptActCollectMission(CharIDType cid)
{
	//接取活动收集任务，参加活动
	OnAttendActivity(g_GetDuplicateCfgMgr()->GetNpcCollectActId(), cid);
}

//每日服答题活动,答正确一题给的奖励
bool LogicActivityModule::RewardActiveDailyAnswerOneSucceed(Player * pPlayer)
{
	LuaScript *pScript = g_GetScriptMgr()->GetScript();
	if (nullptr == pScript)
	{
		LogErrFmtPrint("[center] LogicActivityModule::RewardActiveAnswerOneSucceed....nullptr == pScript... ");
		return 0;
	}
	LuaRef ref(pScript->GetState());
	if (!pScript->CallTableFuncRet("Activity", "GetDailyAnswerBoxReward", ref))
	{
		LogErrFmtPrint("[center] LogicActivityModule::RewardActiveAnswerOneSucceed...pScript->CallTableFuncRet failed....");
		return 0;
	}
	if (!ref.isTable())
	{
		LogErrFmtPrint("[center] LogicActivityModule::RewardActiveAnswerOneSucceed...!ref.isTable() return false....");
		return 0;
	}

	int32_t boxid = ref["box_id"].cast<uint32_t>();;
	uint32_t rate = ref["rate"].cast<int32_t>();

	if (Random(0, 100) < rate)
	{
		//发放奖励
		VEC_INT32 vecBox;
		vecBox.push_back(boxid);
		SItemSourceParam sourceParam;
		if (g_GetDropMgr()->PlayerAddBox(pPlayer, vecBox, sourceParam) != RET_SUCCESS)
		{
			std::vector<ItemProtoInfo> vecProto;
			int32_t gold, bindnum, diamnum;
			BoxCondCfg boncfg;
			g_GetDropMgr()->GetBoxCond(pPlayer, boncfg);
			g_GetItemMgr()->CreateBoxDropItem(boxid, vecProto, gold, diamnum, bindnum, boncfg);
			//发放邮件
			string strTopic = "每日答题";
			string strContent = "你在每日答题活动中，回答正确，获得物品！";
			g_GetGMailMgr()->SendSystemMail(pPlayer->GetId(), strTopic, strContent, 0, 0, 0, 0, 0, vecProto);
		}

		LogDebugFmtPrint("LogicActivityModule::RewardActiveDailyAnswerOneSucceed boxid=%d", boxid);
	}

	return true;
}


bool LogicActivityModule::OnGetWorldAnswerInfo(CharIDType charID, ActivityAnswerInfoReq & req)
{
	ActivityAnswerInfoRsp rsp;
	rsp.set_result(1);
	rsp.set_activetype(enActiveAnswerType_World);
	if (!IsRunningByType(ATI_ANSWER))
	{
		rsp.set_result(0);
	}
	else
	{
		Player * pPlayer = g_GetCreatureMgr()->GetPlayer(charID);
		if (pPlayer)
		{
			const ConstantConstantCfgInfo * pConfigNum = g_GetConstantConstantCfgTable()->GetConstantConstantCfgInfo(EArg_Activity_Answer_Num);
			if (pConfigNum)
			{
				uint32_t maxNum = pConfigNum->constantdata;
				PlayerActiveAnswerData &data = pPlayer->GetPlayerAnswerData();
				rsp.set_isgetreward(data.isgetreward());
				if (data.answerlist_size() <= 0)
				{
					//先随20题出来
					VEC_UINT32 vID;
					g_GetAnswerMgr()->GetAnswerListByType(vID, enActivity_Type_Active);
					//先打乱下
					for (int i = 0; i < (int)maxNum; ++i)
					{
						int rand = Random(0, vID.size() - 1);
						uint32_t tmp = vID[rand];
						vID[rand] = vID[i];
						vID[i] = tmp;
					}

					if (vID.size() < maxNum)
					{
						rsp.set_result(0);
						LogErrFmtPrint("answer activity quest less %d", maxNum);
					}
					else
					{
						for (int i = 0; i < (int)maxNum; ++i)
						{
							data.add_answerlist(vID[i]);
						}

						data.set_answerindex(0);
						rsp.set_answerindex(0); // 发id
						rsp.set_answerid(data.answerlist(0));
						rsp.set_maxanswernum(maxNum);
					}

				}
				else
				{
					if (data.answerindex() < (uint32_t)data.answerlist_size())
					{
						rsp.set_answerid(data.answerlist(data.answerindex())); // 发id
					}

					rsp.set_allmoney(data.allmoney());
					rsp.set_allexp(data.allexp());
					rsp.set_correctnum(data.correctnum());
					rsp.set_answerindex(data.answerindex());
					rsp.set_maxanswernum(maxNum);
				}
			}
		}

	}
	g_GetLogicService()->SendDataToClient(charID, EMODULE_ID_ACTIVITY, LOGIC_TO_CLIENT_ACTIVITY_ANSWER_INFO_RSP, &rsp);

	return true;
}
bool LogicActivityModule::OnGetDailyAnswerInfo(CharIDType charID, ActivityAnswerInfoReq & req)
{
	ActivityAnswerInfoRsp rsp;
	rsp.set_result(0);
	rsp.set_activetype(enActiveAnswerType_Daily);
	if (!IsRunningByType(ATI_DAILY_ANSWER))
	{
		rsp.set_result(1);
	}
	else
	{
		Player * pPlayer = g_GetCreatureMgr()->GetPlayer(charID);
		if (pPlayer)
		{
			const ConstantConstantCfgInfo * pConfigNum = g_GetConstantConstantCfgTable()->GetConstantConstantCfgInfo(EArg_Activity_Daily_Answer_Num);
			if (pConfigNum)
			{
				uint32_t maxNum = pConfigNum->constantdata;
				PlayerActiveAnswerData &data = pPlayer->GetPlayerDailyAnswerData();
				rsp.set_isgetreward(data.isgetreward());
				if (data.answerlist_size() <= 0)
				{
					//先随20题出来
					VEC_UINT32 vID;
					g_GetAnswerMgr()->GetAnswerListByType(vID, enActivity_Type_Active);
					//先打乱下
					for (int i = 0; i < (int)maxNum; ++i)  //把前面10个随机换掉
					{
						int rand = Random(0, vID.size() - 1);
						uint32_t tmp = vID[rand];
						vID[rand] = vID[i];
						vID[i] = tmp;
					}

					if (vID.size() < maxNum)
					{
						rsp.set_result(0);
						LogErrFmtPrint("answer activity quest less %d", maxNum);
					}
					else
					{
						VEC_UINT32 vTmp;
						for (int i = 0; i < (int)maxNum; ++i)
						{
							data.add_answerlist(vID[i]);
						}
						data.set_answerindex(0);
						rsp.set_answerindex(0); // 发id
						rsp.set_answerid(data.answerlist(0));
						rsp.set_maxanswernum(maxNum);
					}

				}
				else
				{
					if (data.answerindex() < (uint32_t)data.answerlist_size())
					{
						rsp.set_answerid(data.answerlist(data.answerindex())); // 发id
					}

					rsp.set_allmoney(data.allmoney());
					rsp.set_allexp(data.allexp());
					rsp.set_correctnum(data.correctnum());
					rsp.set_answerindex(data.answerindex());
					rsp.set_maxanswernum(maxNum);
				}
			}
		}

	}
	g_GetLogicService()->SendDataToClient(charID, EMODULE_ID_ACTIVITY, LOGIC_TO_CLIENT_ACTIVITY_ANSWER_INFO_RSP, &rsp);

	return true;
}
bool LogicActivityModule::OnWorldAnswerResult(CharIDType charID, ActivityAnswerResultReq & req)
{
	if (!IsRunningByType(ATI_ANSWER))
	{
		LogErrFmtPrint("activity close rec answer req cid=%lu", charID);
		return false;
	}

	ActivityAnswerResultRsp rsp;
	rsp.set_result(0);
	rsp.set_activetype(enActiveAnswerType_World);

	Player * pPlayer = g_GetCreatureMgr()->GetPlayer(charID);
	if (pPlayer)
	{
		PlayerActiveAnswerData &data = pPlayer->GetPlayerAnswerData();
		const ConstantConstantCfgInfo * pConfigNum = g_GetConstantConstantCfgTable()->GetConstantConstantCfgInfo(EArg_Activity_Answer_Num);
		if (pConfigNum)
		{
			uint32_t maxNum = pConfigNum->constantdata;

			if ((uint32_t)data.answerindex() >= maxNum || (uint32_t)data.answerlist_size() != maxNum)
			{
				LogErrFmtPrint("LogicActivityModule::OnAnswerResult question index>%d", maxNum);
				return false;
			}
			if ((uint32_t)data.answerlist_size() <= data.answerindex())
			{
				LogErrFmtPrint("LogicActivityModule::OnAnswerResult data.answerlist_size() <= data.answerindex(),size:%d, idx:%d ", data.answerlist_size(), data.answerindex());
				return false;
			}
			if (g_GetAnswerMgr()->IsCorrectAnswer(data.answerlist(data.answerindex()), req.selectid()))
			{
				rsp.set_result(1);

				//有概率给奖励
				RewardActiveAnswerOneSucceed(pPlayer);
			}

			data.set_answerindex(data.answerindex() + 1);


			const ConstantConstantCfgInfo * pConfigExp = g_GetConstantConstantCfgTable()->GetConstantConstantCfgInfo(EArg_Activity_Answer_Reward_Exp);
			const ConstantConstantCfgInfo * pConfigMoney = g_GetConstantConstantCfgTable()->GetConstantConstantCfgInfo(EArg_Activity_Answer_Reward_Money);
			if (!pConfigExp || !pConfigMoney)
			{
				LogErrFmtPrint("activity answer const data error ");
				return false;
			}


			std::vector<int32_t> vParamExp;
			std::vector<int32_t> vParamMoney;
			CommonApi::SplitStrToVecInt(pConfigExp->stringdata, ",", &vParamExp);
			CommonApi::SplitStrToVecInt(pConfigMoney->stringdata, ",", &vParamMoney);
			if (vParamExp.size() != 3 || vParamMoney.size() != 3)
			{
				LogErrFmtPrint("activity answer const param !=3 ");
				return false;
			}


			//给经验
			uint32_t level = pPlayer->GetPAttrValue(P_LEVEL);


			float tmpFloat = 1.0f;
			if (rsp.result() == 0)
			{
				tmpFloat = 0.5f;
			}
			uint32_t exp = (vParamExp[0]/100.0 * level*level + vParamExp[1]/100.0* level + vParamExp[2]/100.0)*tmpFloat;

			uint32_t money = (vParamMoney[0]/100.0 * level*level + vParamMoney[1]/100.0 * level + vParamMoney[2]/100.0)*tmpFloat;

			data.set_allexp(data.allexp() + exp);
			data.set_allmoney(data.allmoney() + money);

			if (rsp.result() == 1)
			{
				data.set_correctnum(data.correctnum() + 1);
			}

			pPlayer->AddExp(exp);
			pPlayer->AddSourceAttr(C_GOLD, money, true, S_ACTIVITY_ANWSER);


			rsp.set_exp(exp);
			rsp.set_money(money);
			if (data.answerindex() < maxNum)
			{
				rsp.set_answerid(data.answerlist(data.answerindex()));
			}

			//表示答完题了，活跃度次数加1
			if (data.answerindex() == maxNum)
			{
				HuoYueDuPart * pHuoYueDuPart = dynamic_cast<HuoYueDuPart*>(pPlayer->GetPart(PART_HUOYUEDU));
				if (pHuoYueDuPart)
				{
					pHuoYueDuPart->AddHuoYueDuRecord(HYDT_ACTIVETY_ANSWER);
				}
			}
			if (1 == rsp.result())
			{
				//答对了，参加世界答题活动
				OnAttendActivity(g_GetDuplicateCfgMgr()->GetWorldAnswerActId(), charID);
				//全部答对了，完成世界答题活动
				if (data.correctnum() >= maxNum)
				{
					OnFinishActivity(g_GetDuplicateCfgMgr()->GetWorldAnswerActId(), charID);
				}
			}

		}

		
	}



	g_GetLogicService()->SendDataToClient(charID, EMODULE_ID_ACTIVITY, LOGIC_TO_CLIENT_ACTIVITY_ANSWER_RESULT, &rsp);


	return true;
}
bool LogicActivityModule::OnDailyAnswerResult(CharIDType charID, ActivityAnswerResultReq & req)
{
	if (!IsRunningByType(ATI_DAILY_ANSWER))
	{
		LogErrFmtPrint("activity close rec answer req cid=%lu", charID);
		return false;
	}

	ActivityAnswerResultRsp rsp;
	rsp.set_result(0);
	rsp.set_activetype(enActiveAnswerType_Daily);

	Player * pPlayer = g_GetCreatureMgr()->GetPlayer(charID);
	if (pPlayer)
	{
		PlayerActiveAnswerData &data = pPlayer->GetPlayerDailyAnswerData();
		const ConstantConstantCfgInfo * pConfigNum = g_GetConstantConstantCfgTable()->GetConstantConstantCfgInfo(EArg_Activity_Daily_Answer_Num);
		if (pConfigNum)
		{
			uint32_t maxNum = pConfigNum->constantdata;

			if ((uint32_t)data.answerindex() >= maxNum || (uint32_t)data.answerlist_size() != maxNum)
			{
				LogErrFmtPrint("LogicActivityModule::OnAnswerResult question index>%d", maxNum);
				return false;
			}
			if ((uint32_t)data.answerlist_size() <= data.answerindex())
			{
				LogErrFmtPrint("LogicActivityModule::OnAnswerResult data.answerlist_size() <= data.answerindex(),size:%d, idx:%d ", data.answerlist_size(), data.answerindex());
				return false;
			}
			if (g_GetAnswerMgr()->IsCorrectAnswer(data.answerlist(data.answerindex()), req.selectid()))
			{
				rsp.set_result(1);

				//有概率给奖励
				RewardActiveDailyAnswerOneSucceed(pPlayer);
			}

			data.set_answerindex(data.answerindex() + 1);


			const ConstantConstantCfgInfo * pConfigExp = g_GetConstantConstantCfgTable()->GetConstantConstantCfgInfo(EArg_Activity_Daily_Answer_Reward_Exp);
			const ConstantConstantCfgInfo * pConfigMoney = g_GetConstantConstantCfgTable()->GetConstantConstantCfgInfo(EArg_Activity_Daily_Answer_Reward_Money);
			if (!pConfigExp || !pConfigMoney)
			{
				LogErrFmtPrint("activity answer const data error ");
				return false;
			}


			std::vector<int32_t> vParamExp;
			std::vector<int32_t> vParamMoney;
			CommonApi::SplitStrToVecInt(pConfigExp->stringdata, ",", &vParamExp);
			CommonApi::SplitStrToVecInt(pConfigMoney->stringdata, ",", &vParamMoney);
			if (vParamExp.size() != 3 || vParamMoney.size() != 3)
			{
				LogErrFmtPrint("activity answer const param !=3 ");
				return false;
			}


			//给经验
			uint32_t level = pPlayer->GetPAttrValue(P_LEVEL);


			float tmpFloat = 1.0f;
			if (rsp.result() == 0)
			{
				tmpFloat = 0.5f;
			}
			uint32_t exp = (vParamExp[0]/100.0 * level*level + vParamExp[1]/100.0 * level + vParamExp[2]/100.0)*tmpFloat;

			uint32_t money = (vParamMoney[0]/100.0 * level*level + vParamMoney[1]/100.0 * level + vParamMoney[2]/100.0)*tmpFloat;

			data.set_allexp(data.allexp() + exp);
			data.set_allmoney(data.allmoney() + money);

			if (rsp.result() == 1)
			{
				data.set_correctnum(data.correctnum() + 1);
			}

			pPlayer->AddExp(exp);
			pPlayer->AddSourceAttr(C_GOLD, money, true, S_ACTIVITY_ANWSER);


			rsp.set_exp(exp);
			rsp.set_money(money);
			if (data.answerindex() < maxNum)
			{
				rsp.set_answerid(data.answerlist(data.answerindex()));
			}

			//表示答完题了，活跃度次数加1
			if (data.answerindex() == maxNum)
			{
				HuoYueDuPart * pHuoYueDuPart = dynamic_cast<HuoYueDuPart*>(pPlayer->GetPart(PART_HUOYUEDU));
				if (pHuoYueDuPart)
				{
					pHuoYueDuPart->AddHuoYueDuRecord(HYDT_ACTIVETY_DAILY_ANSWER);
				}
			}
		}
	}

	g_GetLogicService()->SendDataToClient(charID, EMODULE_ID_ACTIVITY, LOGIC_TO_CLIENT_ACTIVITY_ANSWER_RESULT, &rsp);
	return true;
}
bool LogicActivityModule::OnWorldAnswerGetLastReward(CharIDType charID, ActivityAnswerGetLastRewardReq & req)
{
	ActivityAnswerGetLastRewardRsp rsp;
	rsp.set_result(RET_SUCCESS);
	rsp.set_activetype(enActiveAnswerType_World);
	if (!IsRunningByType(ATI_ANSWER))
	{
		rsp.set_result(RET_ACTIVITY_NOT_OPEN);
	}

	Player * pPlayer = g_GetCreatureMgr()->GetPlayer(charID);
	if (pPlayer)
	{
		PlayerActiveAnswerData &data = pPlayer->GetPlayerAnswerData();

		if (data.isgetreward() == 1)
		{
			rsp.set_result(RET_ACTIVITY_ACTIVE_ANSWER_HAS_GET_REWARD);
		}
		else
		{
			const ConstantConstantCfgInfo * pConfigNum = g_GetConstantConstantCfgTable()->GetConstantConstantCfgInfo(EArg_Activity_Answer_Num);
			if (pConfigNum)
			{
				if ((int32_t)data.correctnum() < pConfigNum->constantdata)
				{
					rsp.set_result(RET_ACTIVITY_ACTIVE_ANSWER_NO_ALL_CORRECT);
				}
				else
				{
					//uint32_t boxID = 0;
					const ItemItemCfgInfo *pItemCfg = g_GetItemItemCfgTable()->GetItemItemCfgInfo(pConfigNum->constantdata);
					if (nullptr == pItemCfg)
					{
						rsp.set_result(RET_FAIL);
					}
					else
					{

						//if ((int32_t)EItemFuncType::EItemFuncType_Box == pItemCfg->functionType)
						//{
						//	const VEC_INT32 *pFuncParam = g_GetItemCfgMgr()->GetItemFuncParamCfg(pConfigNum->constantdata);
						//	if (nullptr != pFuncParam && pFuncParam->size() >= 1)
						//	{
						//		boxID = pFuncParam->at(0);
						//	}
						//}

						//VEC_INT32 vBox;
						//vBox.push_back(boxID);
						//SItemSourceParam sourceParam;
						//sourceParam.notifySource = ENotifyType_Item_WorldAnswer;
						//sourceParam.notifyVal = g_GetDuplicateCfgMgr()->GetWorldAnswerActId();
						//ERetCode retCode = g_GetDropMgr()->PlayerAddBox(pPlayer, vBox, sourceParam);
						//if (retCode == RET_SUCCESS)
						//{
						//	rsp.set_itemid(pConfigNum->constantdata);

						//	data.set_isgetreward(1);
						//}
						//else
						//{
						//	rsp.set_result(retCode);
						//}

						PackagePart * pPackage = dynamic_cast<PackagePart *>(pPlayer->GetPart(PART_PACKAGE));
						SItemSourceParam sourceParam;
						sourceParam.source = S_ACTIVE;
						if (pPackage && pPackage->AddItem(pItemCfg->id, 1, sourceParam))
						{
							rsp.set_itemid(pItemCfg->id);

							data.set_isgetreward(1);
							rsp.set_result(RET_SUCCESS);
						}
						else
						{
							rsp.set_result(RET_FAIL);
						}

					}

				}
			}
		}
	}

	g_GetLogicService()->SendDataToClient(charID, EMODULE_ID_ACTIVITY, LOGIC_TO_CLIENT_ACTIVITY_ANSWER_LAST_REWARD_RESULT, &rsp);

	return true;
}
bool LogicActivityModule::OnDailyAnswerGetLastReward(CharIDType charID, ActivityAnswerGetLastRewardReq & req)
{
	ActivityAnswerGetLastRewardRsp rsp;
	rsp.set_result(RET_SUCCESS);
	rsp.set_activetype(enActiveAnswerType_Daily);
	if (!IsRunningByType(ATI_DAILY_ANSWER))
	{
		rsp.set_result(RET_ACTIVITY_NOT_OPEN);
	}

	Player * pPlayer = g_GetCreatureMgr()->GetPlayer(charID);
	if (pPlayer)
	{
		PlayerActiveAnswerData &data = pPlayer->GetPlayerDailyAnswerData();

		if (data.isgetreward() == 1)
		{
			rsp.set_result(RET_ACTIVITY_ACTIVE_ANSWER_HAS_GET_REWARD);
		}
		else
		{
			const ConstantConstantCfgInfo * pConfigNum = g_GetConstantConstantCfgTable()->GetConstantConstantCfgInfo(EArg_Activity_Daily_Answer_Num);
			if (pConfigNum)
			{
				if ((int32_t)data.correctnum() < pConfigNum->constantdata)
				{
					rsp.set_result(RET_ACTIVITY_ACTIVE_ANSWER_NO_ALL_CORRECT);
				}
				else
				{
					//下发物品
					const ConstantConstantCfgInfo * pConfig = g_GetConstantConstantCfgTable()->GetConstantConstantCfgInfo(EArg_Activity_Daily_Answer_Reward_Item);
					if (pConfig)
					{
						//uint32_t boxID = 0;
						const ItemItemCfgInfo *pItemCfg = g_GetItemItemCfgTable()->GetItemItemCfgInfo(pConfig->constantdata);
						if (nullptr == pItemCfg)
						{
							rsp.set_result(RET_FAIL);
						}
						else
						{

							//if ((int32_t)EItemFuncType::EItemFuncType_Box == pItemCfg->functionType)
							//{
							//	const VEC_INT32 *pFuncParam = g_GetItemCfgMgr()->GetItemFuncParamCfg(pConfig->constantdata);
							//	if (nullptr != pFuncParam && pFuncParam->size() >= 1)
							//	{
							//		boxID = pFuncParam->at(0);
							//	}
							//}

							//VEC_INT32 vBox;
							//vBox.push_back(boxID);
							//SItemSourceParam sourceParam;
							//ERetCode retCode = g_GetDropMgr()->PlayerAddBox(pPlayer, vBox, sourceParam);

							PackagePart * pPackage = dynamic_cast<PackagePart *>(pPlayer->GetPart(PART_PACKAGE));
							SItemSourceParam sourceParam;
							sourceParam.source = S_ACTIVE;
							if (pPackage && pPackage->AddItem(pItemCfg->id, 1, sourceParam))
							{
								rsp.set_itemid(pItemCfg->id);

								data.set_isgetreward(1);
								rsp.set_result(RET_SUCCESS);
							}
							else
							{
								rsp.set_result(RET_FAIL);
							}
						}
					}
					else
					{
						rsp.set_result(RET_FAIL);
					}

				}
			}
		}
	}

	g_GetLogicService()->SendDataToClient(charID, EMODULE_ID_ACTIVITY, LOGIC_TO_CLIENT_ACTIVITY_ANSWER_LAST_REWARD_RESULT, &rsp);

	return true;
}
